From 0e1d9a247b2b6ce850bf733e52668c64ce22371a Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" <12751435+giautm@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:05:02 +0700 Subject: [PATCH] chore: upgrade ent and atlas (#554) * chore: upgrade ent and atlas * fix: bump go version to 1.20 * .ci: upgrade golangci * chore: codegen --- .github/workflows/ci.yml | 10 +- .golangci.yml | 8 +- entgql/internal/todo/ent/billproduct/where.go | 23 +- .../internal/todo/ent/billproduct_create.go | 6 +- .../internal/todo/ent/billproduct_delete.go | 2 +- .../internal/todo/ent/billproduct_update.go | 52 ++- entgql/internal/todo/ent/category/where.go | 23 +- entgql/internal/todo/ent/category_create.go | 6 +- entgql/internal/todo/ent/category_delete.go | 2 +- entgql/internal/todo/ent/category_update.go | 36 +- entgql/internal/todo/ent/client.go | 156 +++++++- entgql/internal/todo/ent/friendship/where.go | 23 +- entgql/internal/todo/ent/friendship_create.go | 6 +- entgql/internal/todo/ent/friendship_delete.go | 2 +- entgql/internal/todo/ent/friendship_update.go | 36 +- entgql/internal/todo/ent/group/where.go | 23 +- entgql/internal/todo/ent/group_create.go | 6 +- entgql/internal/todo/ent/group_delete.go | 2 +- entgql/internal/todo/ent/group_update.go | 4 +- entgql/internal/todo/ent/mutation.go | 4 + entgql/internal/todo/ent/onetomany/where.go | 23 +- entgql/internal/todo/ent/onetomany_create.go | 6 +- entgql/internal/todo/ent/onetomany_delete.go | 2 +- entgql/internal/todo/ent/onetomany_update.go | 20 +- entgql/internal/todo/ent/project/where.go | 23 +- entgql/internal/todo/ent/project_create.go | 6 +- entgql/internal/todo/ent/project_delete.go | 2 +- entgql/internal/todo/ent/project_update.go | 4 +- entgql/internal/todo/ent/runtime/runtime.go | 4 +- entgql/internal/todo/ent/todo/where.go | 23 +- entgql/internal/todo/ent/todo_create.go | 6 +- entgql/internal/todo/ent/todo_delete.go | 2 +- entgql/internal/todo/ent/todo_update.go | 36 +- entgql/internal/todo/ent/user/where.go | 23 +- entgql/internal/todo/ent/user_create.go | 6 +- entgql/internal/todo/ent/user_delete.go | 2 +- entgql/internal/todo/ent/user_update.go | 4 +- entgql/internal/todo/ent/verysecret/where.go | 23 +- entgql/internal/todo/ent/verysecret_create.go | 6 +- entgql/internal/todo/ent/verysecret_delete.go | 2 +- entgql/internal/todo/ent/verysecret_update.go | 20 +- entgql/internal/todo/ent/workspace/where.go | 23 +- entgql/internal/todo/ent/workspace_create.go | 6 +- entgql/internal/todo/ent/workspace_delete.go | 2 +- entgql/internal/todo/ent/workspace_update.go | 20 +- entgql/internal/todo/server/server.go | 7 +- entgql/internal/todofed/ent/category/where.go | 23 +- .../internal/todofed/ent/category_create.go | 6 +- .../internal/todofed/ent/category_delete.go | 2 +- .../internal/todofed/ent/category_update.go | 36 +- entgql/internal/todofed/ent/client.go | 51 ++- .../internal/todofed/ent/runtime/runtime.go | 4 +- entgql/internal/todofed/ent/todo/where.go | 23 +- entgql/internal/todofed/ent/todo_create.go | 6 +- entgql/internal/todofed/ent/todo_delete.go | 2 +- entgql/internal/todofed/ent/todo_update.go | 36 +- .../internal/todofed/ent/verysecret/where.go | 23 +- .../internal/todofed/ent/verysecret_create.go | 6 +- .../internal/todofed/ent/verysecret_delete.go | 2 +- .../internal/todofed/ent/verysecret_update.go | 20 +- entgql/internal/todofed/server/server.go | 7 +- .../todogotype/ent/billproduct/where.go | 23 +- .../todogotype/ent/billproduct_create.go | 6 +- .../todogotype/ent/billproduct_delete.go | 2 +- .../todogotype/ent/billproduct_update.go | 52 ++- .../internal/todogotype/ent/category/where.go | 23 +- .../todogotype/ent/category_create.go | 6 +- .../todogotype/ent/category_delete.go | 2 +- .../todogotype/ent/category_update.go | 36 +- entgql/internal/todogotype/ent/client.go | 126 +++++- .../todogotype/ent/friendship/where.go | 23 +- .../todogotype/ent/friendship_create.go | 6 +- .../todogotype/ent/friendship_delete.go | 2 +- .../todogotype/ent/friendship_update.go | 36 +- entgql/internal/todogotype/ent/group/where.go | 23 +- .../internal/todogotype/ent/group_create.go | 6 +- .../internal/todogotype/ent/group_delete.go | 2 +- .../internal/todogotype/ent/group_update.go | 4 +- entgql/internal/todogotype/ent/mutation.go | 3 + entgql/internal/todogotype/ent/pet/where.go | 23 +- entgql/internal/todogotype/ent/pet_create.go | 6 +- entgql/internal/todogotype/ent/pet_delete.go | 2 +- entgql/internal/todogotype/ent/pet_update.go | 4 +- .../todogotype/ent/runtime/runtime.go | 4 +- entgql/internal/todogotype/ent/todo/where.go | 23 +- entgql/internal/todogotype/ent/todo_create.go | 6 +- entgql/internal/todogotype/ent/todo_delete.go | 2 +- entgql/internal/todogotype/ent/todo_update.go | 36 +- entgql/internal/todogotype/ent/user/where.go | 23 +- entgql/internal/todogotype/ent/user_create.go | 6 +- entgql/internal/todogotype/ent/user_delete.go | 2 +- entgql/internal/todogotype/ent/user_update.go | 4 +- .../todogotype/ent/verysecret/where.go | 23 +- .../todogotype/ent/verysecret_create.go | 6 +- .../todogotype/ent/verysecret_delete.go | 2 +- .../todogotype/ent/verysecret_update.go | 20 +- .../todopulid/ent/billproduct/where.go | 23 +- .../todopulid/ent/billproduct_create.go | 6 +- .../todopulid/ent/billproduct_delete.go | 2 +- .../todopulid/ent/billproduct_update.go | 52 ++- .../internal/todopulid/ent/category/where.go | 23 +- .../internal/todopulid/ent/category_create.go | 6 +- .../internal/todopulid/ent/category_delete.go | 2 +- .../internal/todopulid/ent/category_update.go | 36 +- entgql/internal/todopulid/ent/client.go | 111 +++++- .../todopulid/ent/friendship/where.go | 23 +- .../todopulid/ent/friendship_create.go | 6 +- .../todopulid/ent/friendship_delete.go | 2 +- .../todopulid/ent/friendship_update.go | 36 +- entgql/internal/todopulid/ent/group/where.go | 23 +- entgql/internal/todopulid/ent/group_create.go | 6 +- entgql/internal/todopulid/ent/group_delete.go | 2 +- entgql/internal/todopulid/ent/group_update.go | 4 +- entgql/internal/todopulid/ent/mutation.go | 3 + .../internal/todopulid/ent/runtime/runtime.go | 4 +- entgql/internal/todopulid/ent/todo/where.go | 23 +- entgql/internal/todopulid/ent/todo_create.go | 6 +- entgql/internal/todopulid/ent/todo_delete.go | 2 +- entgql/internal/todopulid/ent/todo_update.go | 36 +- entgql/internal/todopulid/ent/user/where.go | 23 +- entgql/internal/todopulid/ent/user_create.go | 6 +- entgql/internal/todopulid/ent/user_delete.go | 2 +- entgql/internal/todopulid/ent/user_update.go | 4 +- .../todopulid/ent/verysecret/where.go | 23 +- .../todopulid/ent/verysecret_create.go | 6 +- .../todopulid/ent/verysecret_delete.go | 2 +- .../todopulid/ent/verysecret_update.go | 20 +- entgql/internal/todopulid/server/server.go | 7 +- .../todouuid/ent/billproduct/where.go | 23 +- .../todouuid/ent/billproduct_create.go | 6 +- .../todouuid/ent/billproduct_delete.go | 2 +- .../todouuid/ent/billproduct_update.go | 52 ++- .../internal/todouuid/ent/category/where.go | 23 +- .../internal/todouuid/ent/category_create.go | 6 +- .../internal/todouuid/ent/category_delete.go | 2 +- .../internal/todouuid/ent/category_update.go | 36 +- entgql/internal/todouuid/ent/client.go | 111 +++++- .../internal/todouuid/ent/friendship/where.go | 23 +- .../todouuid/ent/friendship_create.go | 6 +- .../todouuid/ent/friendship_delete.go | 2 +- .../todouuid/ent/friendship_update.go | 36 +- entgql/internal/todouuid/ent/group/where.go | 23 +- entgql/internal/todouuid/ent/group_create.go | 6 +- entgql/internal/todouuid/ent/group_delete.go | 2 +- entgql/internal/todouuid/ent/group_update.go | 4 +- entgql/internal/todouuid/ent/mutation.go | 3 + .../internal/todouuid/ent/runtime/runtime.go | 4 +- entgql/internal/todouuid/ent/todo/where.go | 23 +- entgql/internal/todouuid/ent/todo_create.go | 6 +- entgql/internal/todouuid/ent/todo_delete.go | 2 +- entgql/internal/todouuid/ent/todo_update.go | 36 +- entgql/internal/todouuid/ent/user/where.go | 23 +- entgql/internal/todouuid/ent/user_create.go | 6 +- entgql/internal/todouuid/ent/user_delete.go | 2 +- entgql/internal/todouuid/ent/user_update.go | 4 +- .../internal/todouuid/ent/verysecret/where.go | 23 +- .../todouuid/ent/verysecret_create.go | 6 +- .../todouuid/ent/verysecret_delete.go | 2 +- .../todouuid/ent/verysecret_update.go | 20 +- entgql/internal/todouuid/server/server.go | 7 +- entoas/internal/cycle/client.go | 21 +- entoas/internal/cycle/runtime/runtime.go | 4 +- entoas/internal/cycle/user/where.go | 23 +- entoas/internal/cycle/user_create.go | 6 +- entoas/internal/cycle/user_delete.go | 2 +- entoas/internal/cycle/user_update.go | 4 +- entoas/internal/oastypes/client.go | 21 +- entoas/internal/oastypes/oastypes/where.go | 23 +- entoas/internal/oastypes/oastypes_create.go | 6 +- entoas/internal/oastypes/oastypes_delete.go | 2 +- entoas/internal/oastypes/oastypes_update.go | 308 ++++++++++++++- entoas/internal/oastypes/runtime/runtime.go | 4 +- entoas/internal/pets/category/where.go | 23 +- entoas/internal/pets/category_create.go | 6 +- entoas/internal/pets/category_delete.go | 2 +- entoas/internal/pets/category_update.go | 20 +- entoas/internal/pets/client.go | 51 ++- entoas/internal/pets/pet/where.go | 23 +- entoas/internal/pets/pet_create.go | 6 +- entoas/internal/pets/pet_delete.go | 2 +- entoas/internal/pets/pet_update.go | 20 +- entoas/internal/pets/runtime/runtime.go | 4 +- entoas/internal/pets/user/where.go | 23 +- entoas/internal/pets/user_create.go | 6 +- entoas/internal/pets/user_delete.go | 2 +- entoas/internal/pets/user_update.go | 36 +- entoas/internal/simple/category/where.go | 23 +- entoas/internal/simple/category_create.go | 6 +- entoas/internal/simple/category_delete.go | 2 +- entoas/internal/simple/category_update.go | 52 ++- entoas/internal/simple/client.go | 51 ++- entoas/internal/simple/pet/where.go | 23 +- entoas/internal/simple/pet_create.go | 6 +- entoas/internal/simple/pet_delete.go | 2 +- entoas/internal/simple/pet_update.go | 20 +- entoas/internal/simple/runtime/runtime.go | 4 +- entoas/internal/simple/user/where.go | 23 +- entoas/internal/simple/user_create.go | 6 +- entoas/internal/simple/user_delete.go | 2 +- entoas/internal/simple/user_update.go | 36 +- entproto/Dockerfile | 2 +- .../internal/todo/ent/attachment/where.go | 23 +- .../internal/todo/ent/attachment_create.go | 6 +- .../internal/todo/ent/attachment_delete.go | 2 +- .../internal/todo/ent/attachment_update.go | 20 +- .../internal/todo/ent/client.go | 66 +++- .../internal/todo/ent/file/where.go | 23 +- .../internal/todo/ent/file_create.go | 6 +- .../internal/todo/ent/file_delete.go | 2 +- .../internal/todo/ent/file_update.go | 20 +- .../internal/todo/ent/runtime/runtime.go | 4 +- .../internal/todo/ent/task/where.go | 23 +- .../internal/todo/ent/task_create.go | 6 +- .../internal/todo/ent/task_delete.go | 2 +- .../internal/todo/ent/task_update.go | 36 +- .../internal/todo/ent/user/where.go | 23 +- .../internal/todo/ent/user_create.go | 6 +- .../internal/todo/ent/user_delete.go | 2 +- .../internal/todo/ent/user_update.go | 20 +- entproto/internal/altdir/ent/client.go | 21 +- .../internal/altdir/ent/runtime/runtime.go | 4 +- entproto/internal/altdir/ent/user/where.go | 23 +- entproto/internal/altdir/ent/user_create.go | 6 +- entproto/internal/altdir/ent/user_delete.go | 2 +- entproto/internal/altdir/ent/user_update.go | 20 +- entproto/internal/bare/ent/client.go | 21 +- entproto/internal/bare/ent/runtime/runtime.go | 4 +- entproto/internal/bare/ent/user/where.go | 23 +- entproto/internal/bare/ent/user_create.go | 6 +- entproto/internal/bare/ent/user_delete.go | 2 +- entproto/internal/bare/ent/user_update.go | 36 +- .../ent/allmethodsservice/where.go | 23 +- .../ent/allmethodsservice_create.go | 6 +- .../ent/allmethodsservice_delete.go | 2 +- .../ent/allmethodsservice_update.go | 4 +- .../entprototest/ent/blogpost/where.go | 23 +- .../entprototest/ent/blogpost_create.go | 6 +- .../entprototest/ent/blogpost_delete.go | 2 +- .../entprototest/ent/blogpost_update.go | 52 ++- .../entprototest/ent/category/where.go | 23 +- .../entprototest/ent/category_create.go | 6 +- .../entprototest/ent/category_delete.go | 2 +- .../entprototest/ent/category_update.go | 36 +- entproto/internal/entprototest/ent/client.go | 366 +++++++++++++++++- .../ent/dependsonskipped/where.go | 23 +- .../ent/dependsonskipped_create.go | 6 +- .../ent/dependsonskipped_delete.go | 2 +- .../ent/dependsonskipped_update.go | 20 +- .../ent/duplicatenumbermessage/where.go | 23 +- .../ent/duplicatenumbermessage_create.go | 6 +- .../ent/duplicatenumbermessage_delete.go | 2 +- .../ent/duplicatenumbermessage_update.go | 36 +- .../ent/enumwithconflictingvalue/where.go | 23 +- .../ent/enumwithconflictingvalue_create.go | 6 +- .../ent/enumwithconflictingvalue_delete.go | 2 +- .../ent/enumwithconflictingvalue_update.go | 20 +- .../ent/explicitskippedmessage/where.go | 23 +- .../ent/explicitskippedmessage_create.go | 6 +- .../ent/explicitskippedmessage_delete.go | 2 +- .../ent/explicitskippedmessage_update.go | 4 +- .../internal/entprototest/ent/image/where.go | 23 +- .../internal/entprototest/ent/image_create.go | 6 +- .../internal/entprototest/ent/image_delete.go | 2 +- .../internal/entprototest/ent/image_update.go | 20 +- .../ent/implicitskippedmessage/where.go | 23 +- .../ent/implicitskippedmessage_create.go | 6 +- .../ent/implicitskippedmessage_delete.go | 2 +- .../ent/implicitskippedmessage_update.go | 4 +- .../ent/invalidfieldmessage/where.go | 23 +- .../ent/invalidfieldmessage_create.go | 6 +- .../ent/invalidfieldmessage_delete.go | 2 +- .../ent/invalidfieldmessage_update.go | 4 +- .../entprototest/ent/messagewithenum/where.go | 23 +- .../ent/messagewithenum_create.go | 6 +- .../ent/messagewithenum_delete.go | 2 +- .../ent/messagewithenum_update.go | 36 +- .../ent/messagewithfieldone/where.go | 23 +- .../ent/messagewithfieldone_create.go | 6 +- .../ent/messagewithfieldone_delete.go | 2 +- .../ent/messagewithfieldone_update.go | 20 +- .../entprototest/ent/messagewithid/where.go | 23 +- .../entprototest/ent/messagewithid_create.go | 6 +- .../entprototest/ent/messagewithid_delete.go | 2 +- .../entprototest/ent/messagewithid_update.go | 4 +- .../entprototest/ent/messagewithints/where.go | 23 +- .../ent/messagewithints_create.go | 6 +- .../ent/messagewithints_delete.go | 2 +- .../ent/messagewithints_update.go | 4 +- .../ent/messagewithoptionals/where.go | 23 +- .../ent/messagewithoptionals_create.go | 6 +- .../ent/messagewithoptionals_delete.go | 2 +- .../ent/messagewithoptionals_update.go | 4 +- .../ent/messagewithpackagename/where.go | 23 +- .../ent/messagewithpackagename_create.go | 6 +- .../ent/messagewithpackagename_delete.go | 2 +- .../ent/messagewithpackagename_update.go | 20 +- .../ent/messagewithstrings/where.go | 23 +- .../ent/messagewithstrings_create.go | 6 +- .../ent/messagewithstrings_delete.go | 2 +- .../ent/messagewithstrings_update.go | 4 +- .../entprototest/ent/nobackref/where.go | 23 +- .../entprototest/ent/nobackref_create.go | 6 +- .../entprototest/ent/nobackref_delete.go | 2 +- .../entprototest/ent/nobackref_update.go | 4 +- .../ent/onemethodservice/where.go | 23 +- .../ent/onemethodservice_create.go | 6 +- .../ent/onemethodservice_delete.go | 2 +- .../ent/onemethodservice_update.go | 4 +- .../internal/entprototest/ent/portal/where.go | 23 +- .../entprototest/ent/portal_create.go | 6 +- .../entprototest/ent/portal_delete.go | 2 +- .../entprototest/ent/portal_update.go | 36 +- .../entprototest/ent/runtime/runtime.go | 4 +- .../entprototest/ent/skipedgeexample/where.go | 23 +- .../ent/skipedgeexample_create.go | 6 +- .../ent/skipedgeexample_delete.go | 2 +- .../ent/skipedgeexample_update.go | 4 +- .../ent/twomethodservice/where.go | 23 +- .../ent/twomethodservice_create.go | 6 +- .../ent/twomethodservice_delete.go | 2 +- .../ent/twomethodservice_update.go | 4 +- .../internal/entprototest/ent/user/where.go | 23 +- .../internal/entprototest/ent/user_create.go | 6 +- .../internal/entprototest/ent/user_delete.go | 2 +- .../internal/entprototest/ent/user_update.go | 36 +- .../entprototest/ent/validmessage/where.go | 23 +- .../entprototest/ent/validmessage_create.go | 6 +- .../entprototest/ent/validmessage_delete.go | 2 +- .../entprototest/ent/validmessage_update.go | 68 +++- .../internal/todo/ent/attachment/where.go | 23 +- .../internal/todo/ent/attachment_create.go | 6 +- .../internal/todo/ent/attachment_delete.go | 2 +- .../internal/todo/ent/attachment_update.go | 4 +- entproto/internal/todo/ent/client.go | 141 ++++++- entproto/internal/todo/ent/group/where.go | 23 +- entproto/internal/todo/ent/group_create.go | 6 +- entproto/internal/todo/ent/group_delete.go | 2 +- entproto/internal/todo/ent/group_update.go | 20 +- .../todo/ent/multiwordschema/where.go | 23 +- .../todo/ent/multiwordschema_create.go | 6 +- .../todo/ent/multiwordschema_delete.go | 2 +- .../todo/ent/multiwordschema_update.go | 4 +- .../internal/todo/ent/nilexample/where.go | 23 +- .../internal/todo/ent/nilexample_create.go | 6 +- .../internal/todo/ent/nilexample_delete.go | 2 +- .../internal/todo/ent/nilexample_update.go | 4 +- entproto/internal/todo/ent/pet/where.go | 23 +- entproto/internal/todo/ent/pet_create.go | 6 +- entproto/internal/todo/ent/pet_delete.go | 2 +- entproto/internal/todo/ent/pet_update.go | 4 +- entproto/internal/todo/ent/pony/where.go | 23 +- entproto/internal/todo/ent/pony_create.go | 6 +- entproto/internal/todo/ent/pony_delete.go | 2 +- entproto/internal/todo/ent/pony_update.go | 20 +- entproto/internal/todo/ent/runtime/runtime.go | 4 +- .../todo/ent/skipedgeexample/where.go | 23 +- .../todo/ent/skipedgeexample_create.go | 6 +- .../todo/ent/skipedgeexample_delete.go | 2 +- .../todo/ent/skipedgeexample_update.go | 4 +- entproto/internal/todo/ent/todo/where.go | 23 +- entproto/internal/todo/ent/todo_create.go | 6 +- entproto/internal/todo/ent/todo_delete.go | 2 +- entproto/internal/todo/ent/todo_update.go | 20 +- entproto/internal/todo/ent/user/where.go | 23 +- entproto/internal/todo/ent/user_create.go | 6 +- entproto/internal/todo/ent/user_delete.go | 2 +- entproto/internal/todo/ent/user_update.go | 148 ++++++- entproto/internal/todo/generate_test.go | 2 +- go.mod | 6 +- go.sum | 8 +- schemast/internal/loadtest/ent/client.go | 21 +- .../internal/loadtest/ent/message/where.go | 23 +- .../internal/loadtest/ent/message_create.go | 6 +- .../internal/loadtest/ent/message_delete.go | 2 +- .../internal/loadtest/ent/message_update.go | 4 +- .../internal/loadtest/ent/runtime/runtime.go | 4 +- schemast/internal/mutatetest/ent/client.go | 81 +++- .../mutatetest/ent/runtime/runtime.go | 4 +- .../internal/mutatetest/ent/user/where.go | 23 +- .../internal/mutatetest/ent/user_create.go | 6 +- .../internal/mutatetest/ent/user_delete.go | 2 +- .../internal/mutatetest/ent/user_update.go | 4 +- .../mutatetest/ent/withfields/where.go | 23 +- .../mutatetest/ent/withfields_create.go | 6 +- .../mutatetest/ent/withfields_delete.go | 2 +- .../mutatetest/ent/withfields_update.go | 20 +- .../mutatetest/ent/withmodifiedfield/where.go | 23 +- .../ent/withmodifiedfield_create.go | 6 +- .../ent/withmodifiedfield_delete.go | 2 +- .../ent/withmodifiedfield_update.go | 4 +- .../mutatetest/ent/withnilfields/where.go | 23 +- .../mutatetest/ent/withnilfields_create.go | 6 +- .../mutatetest/ent/withnilfields_delete.go | 2 +- .../mutatetest/ent/withnilfields_update.go | 4 +- .../mutatetest/ent/withoutfields/where.go | 23 +- .../mutatetest/ent/withoutfields_create.go | 6 +- .../mutatetest/ent/withoutfields_delete.go | 2 +- .../mutatetest/ent/withoutfields_update.go | 4 +- schemast/internal/printtest/ent/client.go | 36 +- .../internal/printtest/ent/message/where.go | 23 +- .../internal/printtest/ent/message_create.go | 6 +- .../internal/printtest/ent/message_delete.go | 2 +- .../internal/printtest/ent/message_update.go | 4 +- .../internal/printtest/ent/runtime/runtime.go | 4 +- schemast/internal/printtest/ent/user/where.go | 23 +- .../internal/printtest/ent/user_create.go | 6 +- .../internal/printtest/ent/user_delete.go | 2 +- .../internal/printtest/ent/user_update.go | 4 +- 408 files changed, 4416 insertions(+), 2235 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8d455f44..c6ecf6ad4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,16 +16,16 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.21 - name: Run linters - uses: golangci/golangci-lint-action@v3.2.0 + uses: golangci/golangci-lint-action@v3.7.0 with: - version: v1.48.0 + version: v1.55.2 test: runs-on: ubuntu-latest strategy: matrix: - go: ['1.18', '1.19'] + go: ['1.20', '1.21'] steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 @@ -47,7 +47,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '1.19' + go-version: '1.21' - uses: actions/cache@v3 with: path: ~/go/pkg/mod diff --git a/.golangci.yml b/.golangci.yml index 489c63651..a75024d9f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ run: - go: '1.19' + go: '1.21' timeout: 10m linters-settings: @@ -25,13 +25,11 @@ linters: disable-all: true enable: - bodyclose - - deadcode - - depguard - dogsled - dupl - errcheck - gocritic - # - gofmt; Enable back when upgrading CI to Go 1.20. + # - gofmt; disabled because it conflicts with goheader - goheader - gosec - gosimple @@ -39,12 +37,10 @@ linters: - ineffassign - misspell - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unused - - varcheck - whitespace issues: diff --git a/entgql/internal/todo/ent/billproduct/where.go b/entgql/internal/todo/ent/billproduct/where.go index abe1aeb37..59a129e88 100644 --- a/entgql/internal/todo/ent/billproduct/where.go +++ b/entgql/internal/todo/ent/billproduct/where.go @@ -253,32 +253,15 @@ func QuantityLTE(v uint64) predicate.BillProduct { // And groups predicates with the AND operator between them. func And(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.BillProduct(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/billproduct_create.go b/entgql/internal/todo/ent/billproduct_create.go index 088ca3ca5..41a92756f 100644 --- a/entgql/internal/todo/ent/billproduct_create.go +++ b/entgql/internal/todo/ent/billproduct_create.go @@ -58,7 +58,7 @@ func (bpc *BillProductCreate) Mutation() *BillProductMutation { // Save creates the BillProduct in the database. func (bpc *BillProductCreate) Save(ctx context.Context) (*BillProduct, error) { - return withHooks[*BillProduct, BillProductMutation](ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) + return withHooks(ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -138,11 +138,15 @@ func (bpc *BillProductCreate) createSpec() (*BillProduct, *sqlgraph.CreateSpec) // BillProductCreateBulk is the builder for creating many BillProduct entities in bulk. type BillProductCreateBulk struct { config + err error builders []*BillProductCreate } // Save creates the BillProduct entities in the database. func (bpcb *BillProductCreateBulk) Save(ctx context.Context) ([]*BillProduct, error) { + if bpcb.err != nil { + return nil, bpcb.err + } specs := make([]*sqlgraph.CreateSpec, len(bpcb.builders)) nodes := make([]*BillProduct, len(bpcb.builders)) mutators := make([]Mutator, len(bpcb.builders)) diff --git a/entgql/internal/todo/ent/billproduct_delete.go b/entgql/internal/todo/ent/billproduct_delete.go index deac9d1d6..a68cffab7 100644 --- a/entgql/internal/todo/ent/billproduct_delete.go +++ b/entgql/internal/todo/ent/billproduct_delete.go @@ -41,7 +41,7 @@ func (bpd *BillProductDelete) Where(ps ...predicate.BillProduct) *BillProductDel // Exec executes the deletion query and returns how many vertices were deleted. func (bpd *BillProductDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) + return withHooks(ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/billproduct_update.go b/entgql/internal/todo/ent/billproduct_update.go index 4624cb8b2..09a50f97a 100644 --- a/entgql/internal/todo/ent/billproduct_update.go +++ b/entgql/internal/todo/ent/billproduct_update.go @@ -48,12 +48,28 @@ func (bpu *BillProductUpdate) SetName(s string) *BillProductUpdate { return bpu } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableName(s *string) *BillProductUpdate { + if s != nil { + bpu.SetName(*s) + } + return bpu +} + // SetSku sets the "sku" field. func (bpu *BillProductUpdate) SetSku(s string) *BillProductUpdate { bpu.mutation.SetSku(s) return bpu } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableSku(s *string) *BillProductUpdate { + if s != nil { + bpu.SetSku(*s) + } + return bpu +} + // SetQuantity sets the "quantity" field. func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { bpu.mutation.ResetQuantity() @@ -61,6 +77,14 @@ func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { return bpu } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableQuantity(u *uint64) *BillProductUpdate { + if u != nil { + bpu.SetQuantity(*u) + } + return bpu +} + // AddQuantity adds u to the "quantity" field. func (bpu *BillProductUpdate) AddQuantity(u int64) *BillProductUpdate { bpu.mutation.AddQuantity(u) @@ -74,7 +98,7 @@ func (bpu *BillProductUpdate) Mutation() *BillProductMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (bpu *BillProductUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) + return withHooks(ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -154,12 +178,28 @@ func (bpuo *BillProductUpdateOne) SetName(s string) *BillProductUpdateOne { return bpuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableName(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetName(*s) + } + return bpuo +} + // SetSku sets the "sku" field. func (bpuo *BillProductUpdateOne) SetSku(s string) *BillProductUpdateOne { bpuo.mutation.SetSku(s) return bpuo } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableSku(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetSku(*s) + } + return bpuo +} + // SetQuantity sets the "quantity" field. func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { bpuo.mutation.ResetQuantity() @@ -167,6 +207,14 @@ func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { return bpuo } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableQuantity(u *uint64) *BillProductUpdateOne { + if u != nil { + bpuo.SetQuantity(*u) + } + return bpuo +} + // AddQuantity adds u to the "quantity" field. func (bpuo *BillProductUpdateOne) AddQuantity(u int64) *BillProductUpdateOne { bpuo.mutation.AddQuantity(u) @@ -193,7 +241,7 @@ func (bpuo *BillProductUpdateOne) Select(field string, fields ...string) *BillPr // Save executes the query and returns the updated BillProduct entity. func (bpuo *BillProductUpdateOne) Save(ctx context.Context) (*BillProduct, error) { - return withHooks[*BillProduct, BillProductMutation](ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) + return withHooks(ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/category/where.go b/entgql/internal/todo/ent/category/where.go index 2396b7fd7..f885ac6a0 100644 --- a/entgql/internal/todo/ent/category/where.go +++ b/entgql/internal/todo/ent/category/where.go @@ -408,32 +408,15 @@ func HasSubCategoriesWith(preds ...predicate.Category) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/category_create.go b/entgql/internal/todo/ent/category_create.go index ccb22f27c..7944e8b7d 100644 --- a/entgql/internal/todo/ent/category_create.go +++ b/entgql/internal/todo/ent/category_create.go @@ -137,7 +137,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -278,11 +278,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entgql/internal/todo/ent/category_delete.go b/entgql/internal/todo/ent/category_delete.go index 79bb5fa56..f2419242d 100644 --- a/entgql/internal/todo/ent/category_delete.go +++ b/entgql/internal/todo/ent/category_delete.go @@ -41,7 +41,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/category_update.go b/entgql/internal/todo/ent/category_update.go index 668172f88..f0bf2aa58 100644 --- a/entgql/internal/todo/ent/category_update.go +++ b/entgql/internal/todo/ent/category_update.go @@ -52,12 +52,28 @@ func (cu *CategoryUpdate) SetText(s string) *CategoryUpdate { return cu } +// SetNillableText sets the "text" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableText(s *string) *CategoryUpdate { + if s != nil { + cu.SetText(*s) + } + return cu +} + // SetStatus sets the "status" field. func (cu *CategoryUpdate) SetStatus(c category.Status) *CategoryUpdate { cu.mutation.SetStatus(c) return cu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableStatus(c *category.Status) *CategoryUpdate { + if c != nil { + cu.SetStatus(*c) + } + return cu +} + // SetConfig sets the "config" field. func (cu *CategoryUpdate) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdate { cu.mutation.SetConfig(sc) @@ -233,7 +249,7 @@ func (cu *CategoryUpdate) RemoveSubCategories(c ...*Category) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -456,12 +472,28 @@ func (cuo *CategoryUpdateOne) SetText(s string) *CategoryUpdateOne { return cuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableText(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetText(*s) + } + return cuo +} + // SetStatus sets the "status" field. func (cuo *CategoryUpdateOne) SetStatus(c category.Status) *CategoryUpdateOne { cuo.mutation.SetStatus(c) return cuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableStatus(c *category.Status) *CategoryUpdateOne { + if c != nil { + cuo.SetStatus(*c) + } + return cuo +} + // SetConfig sets the "config" field. func (cuo *CategoryUpdateOne) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdateOne { cuo.mutation.SetConfig(sc) @@ -650,7 +682,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/client.go b/entgql/internal/todo/ent/client.go index 3315eecd5..9fe781b77 100644 --- a/entgql/internal/todo/ent/client.go +++ b/entgql/internal/todo/ent/client.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entgql/internal/todo/ent/migrate" "entgo.io/ent" @@ -157,11 +158,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -319,6 +323,21 @@ func (c *BillProductClient) CreateBulk(builders ...*BillProductCreate) *BillProd return &BillProductCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *BillProductClient) MapCreateBulk(slice any, setFunc func(*BillProductCreate, int)) *BillProductCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &BillProductCreateBulk{err: fmt.Errorf("calling to BillProductClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*BillProductCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &BillProductCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for BillProduct. func (c *BillProductClient) Update() *BillProductUpdate { mutation := newBillProductMutation(c.config, OpUpdate) @@ -437,6 +456,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -587,6 +621,21 @@ func (c *FriendshipClient) CreateBulk(builders ...*FriendshipCreate) *Friendship return &FriendshipCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *FriendshipClient) MapCreateBulk(slice any, setFunc func(*FriendshipCreate, int)) *FriendshipCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &FriendshipCreateBulk{err: fmt.Errorf("calling to FriendshipClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*FriendshipCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &FriendshipCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Friendship. func (c *FriendshipClient) Update() *FriendshipUpdate { mutation := newFriendshipMutation(c.config, OpUpdate) @@ -737,6 +786,21 @@ func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { return &GroupCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Group. func (c *GroupClient) Update() *GroupUpdate { mutation := newGroupMutation(c.config, OpUpdate) @@ -871,6 +935,21 @@ func (c *OneToManyClient) CreateBulk(builders ...*OneToManyCreate) *OneToManyCre return &OneToManyCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *OneToManyClient) MapCreateBulk(slice any, setFunc func(*OneToManyCreate, int)) *OneToManyCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &OneToManyCreateBulk{err: fmt.Errorf("calling to OneToManyClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*OneToManyCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &OneToManyCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for OneToMany. func (c *OneToManyClient) Update() *OneToManyUpdate { mutation := newOneToManyMutation(c.config, OpUpdate) @@ -1021,6 +1100,21 @@ func (c *ProjectClient) CreateBulk(builders ...*ProjectCreate) *ProjectCreateBul return &ProjectCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ProjectClient) MapCreateBulk(slice any, setFunc func(*ProjectCreate, int)) *ProjectCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ProjectCreateBulk{err: fmt.Errorf("calling to ProjectClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ProjectCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ProjectCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Project. func (c *ProjectClient) Update() *ProjectUpdate { mutation := newProjectMutation(c.config, OpUpdate) @@ -1155,6 +1249,21 @@ func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk { return &TodoCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TodoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TodoCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Todo. func (c *TodoClient) Update() *TodoUpdate { mutation := newTodoMutation(c.config, OpUpdate) @@ -1337,6 +1446,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) @@ -1503,6 +1627,21 @@ func (c *VerySecretClient) CreateBulk(builders ...*VerySecretCreate) *VerySecret return &VerySecretCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *VerySecretClient) MapCreateBulk(slice any, setFunc func(*VerySecretCreate, int)) *VerySecretCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &VerySecretCreateBulk{err: fmt.Errorf("calling to VerySecretClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*VerySecretCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &VerySecretCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for VerySecret. func (c *VerySecretClient) Update() *VerySecretUpdate { mutation := newVerySecretMutation(c.config, OpUpdate) @@ -1621,6 +1760,21 @@ func (c *WorkspaceClient) CreateBulk(builders ...*WorkspaceCreate) *WorkspaceCre return &WorkspaceCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *WorkspaceClient) MapCreateBulk(slice any, setFunc func(*WorkspaceCreate, int)) *WorkspaceCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &WorkspaceCreateBulk{err: fmt.Errorf("calling to WorkspaceClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*WorkspaceCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &WorkspaceCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Workspace. func (c *WorkspaceClient) Update() *WorkspaceUpdate { mutation := newWorkspaceMutation(c.config, OpUpdate) diff --git a/entgql/internal/todo/ent/friendship/where.go b/entgql/internal/todo/ent/friendship/where.go index 03fb00251..01bfa9881 100644 --- a/entgql/internal/todo/ent/friendship/where.go +++ b/entgql/internal/todo/ent/friendship/where.go @@ -212,32 +212,15 @@ func HasFriendWith(preds ...predicate.User) predicate.Friendship { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Friendship(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/friendship_create.go b/entgql/internal/todo/ent/friendship_create.go index 1c5daaf1c..75e280efe 100644 --- a/entgql/internal/todo/ent/friendship_create.go +++ b/entgql/internal/todo/ent/friendship_create.go @@ -79,7 +79,7 @@ func (fc *FriendshipCreate) Mutation() *FriendshipMutation { // Save creates the Friendship in the database. func (fc *FriendshipCreate) Save(ctx context.Context) (*Friendship, error) { fc.defaults() - return withHooks[*Friendship, FriendshipMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) + return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -199,11 +199,15 @@ func (fc *FriendshipCreate) createSpec() (*Friendship, *sqlgraph.CreateSpec) { // FriendshipCreateBulk is the builder for creating many Friendship entities in bulk. type FriendshipCreateBulk struct { config + err error builders []*FriendshipCreate } // Save creates the Friendship entities in the database. func (fcb *FriendshipCreateBulk) Save(ctx context.Context) ([]*Friendship, error) { + if fcb.err != nil { + return nil, fcb.err + } specs := make([]*sqlgraph.CreateSpec, len(fcb.builders)) nodes := make([]*Friendship, len(fcb.builders)) mutators := make([]Mutator, len(fcb.builders)) diff --git a/entgql/internal/todo/ent/friendship_delete.go b/entgql/internal/todo/ent/friendship_delete.go index 603750fb2..198391f4d 100644 --- a/entgql/internal/todo/ent/friendship_delete.go +++ b/entgql/internal/todo/ent/friendship_delete.go @@ -41,7 +41,7 @@ func (fd *FriendshipDelete) Where(ps ...predicate.Friendship) *FriendshipDelete // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FriendshipDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) + return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/friendship_update.go b/entgql/internal/todo/ent/friendship_update.go index 9d00a2a9c..4ddcb5853 100644 --- a/entgql/internal/todo/ent/friendship_update.go +++ b/entgql/internal/todo/ent/friendship_update.go @@ -64,12 +64,28 @@ func (fu *FriendshipUpdate) SetUserID(i int) *FriendshipUpdate { return fu } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableUserID(i *int) *FriendshipUpdate { + if i != nil { + fu.SetUserID(*i) + } + return fu +} + // SetFriendID sets the "friend_id" field. func (fu *FriendshipUpdate) SetFriendID(i int) *FriendshipUpdate { fu.mutation.SetFriendID(i) return fu } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableFriendID(i *int) *FriendshipUpdate { + if i != nil { + fu.SetFriendID(*i) + } + return fu +} + // SetUser sets the "user" edge to the User entity. func (fu *FriendshipUpdate) SetUser(u *User) *FriendshipUpdate { return fu.SetUserID(u.ID) @@ -99,7 +115,7 @@ func (fu *FriendshipUpdate) ClearFriend() *FriendshipUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FriendshipUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) + return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -256,12 +272,28 @@ func (fuo *FriendshipUpdateOne) SetUserID(i int) *FriendshipUpdateOne { return fuo } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableUserID(i *int) *FriendshipUpdateOne { + if i != nil { + fuo.SetUserID(*i) + } + return fuo +} + // SetFriendID sets the "friend_id" field. func (fuo *FriendshipUpdateOne) SetFriendID(i int) *FriendshipUpdateOne { fuo.mutation.SetFriendID(i) return fuo } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableFriendID(i *int) *FriendshipUpdateOne { + if i != nil { + fuo.SetFriendID(*i) + } + return fuo +} + // SetUser sets the "user" edge to the User entity. func (fuo *FriendshipUpdateOne) SetUser(u *User) *FriendshipUpdateOne { return fuo.SetUserID(u.ID) @@ -304,7 +336,7 @@ func (fuo *FriendshipUpdateOne) Select(field string, fields ...string) *Friendsh // Save executes the query and returns the updated Friendship entity. func (fuo *FriendshipUpdateOne) Save(ctx context.Context) (*Friendship, error) { - return withHooks[*Friendship, FriendshipMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) + return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/group/where.go b/entgql/internal/todo/ent/group/where.go index c7431e161..6867a1aa7 100644 --- a/entgql/internal/todo/ent/group/where.go +++ b/entgql/internal/todo/ent/group/where.go @@ -162,32 +162,15 @@ func HasUsersWith(preds ...predicate.User) predicate.Group { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Group(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/group_create.go b/entgql/internal/todo/ent/group_create.go index f1e5b1cbc..930535566 100644 --- a/entgql/internal/todo/ent/group_create.go +++ b/entgql/internal/todo/ent/group_create.go @@ -71,7 +71,7 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { gc.defaults() - return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) + return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -161,11 +161,15 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { // GroupCreateBulk is the builder for creating many Group entities in bulk. type GroupCreateBulk struct { config + err error builders []*GroupCreate } // Save creates the Group entities in the database. func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { + if gcb.err != nil { + return nil, gcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gcb.builders)) nodes := make([]*Group, len(gcb.builders)) mutators := make([]Mutator, len(gcb.builders)) diff --git a/entgql/internal/todo/ent/group_delete.go b/entgql/internal/todo/ent/group_delete.go index 98b19527b..ea2b595db 100644 --- a/entgql/internal/todo/ent/group_delete.go +++ b/entgql/internal/todo/ent/group_delete.go @@ -41,7 +41,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) + return withHooks(ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/group_update.go b/entgql/internal/todo/ent/group_update.go index b4c02df09..167eabe09 100644 --- a/entgql/internal/todo/ent/group_update.go +++ b/entgql/internal/todo/ent/group_update.go @@ -100,7 +100,7 @@ func (gu *GroupUpdate) RemoveUsers(u ...*User) *GroupUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) + return withHooks(ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -280,7 +280,7 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { - return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) + return withHooks(ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/mutation.go b/entgql/internal/todo/ent/mutation.go index 7987ee637..70e8290ad 100644 --- a/entgql/internal/todo/ent/mutation.go +++ b/entgql/internal/todo/ent/mutation.go @@ -1776,6 +1776,7 @@ func (m *FriendshipMutation) ResetFriendID() { // ClearUser clears the "user" edge to the User entity. func (m *FriendshipMutation) ClearUser() { m.cleareduser = true + m.clearedFields[friendship.FieldUserID] = struct{}{} } // UserCleared reports if the "user" edge to the User entity was cleared. @@ -1802,6 +1803,7 @@ func (m *FriendshipMutation) ResetUser() { // ClearFriend clears the "friend" edge to the User entity. func (m *FriendshipMutation) ClearFriend() { m.clearedfriend = true + m.clearedFields[friendship.FieldFriendID] = struct{}{} } // FriendCleared reports if the "friend" edge to the User entity was cleared. @@ -2758,6 +2760,7 @@ func (m *OneToManyMutation) ResetParentID() { // ClearParent clears the "parent" edge to the OneToMany entity. func (m *OneToManyMutation) ClearParent() { m.clearedparent = true + m.clearedFields[onetomany.FieldParentID] = struct{}{} } // ParentCleared reports if the "parent" edge to the OneToMany entity was cleared. @@ -4144,6 +4147,7 @@ func (m *TodoMutation) ResetChildren() { // ClearCategory clears the "category" edge to the Category entity. func (m *TodoMutation) ClearCategory() { m.clearedcategory = true + m.clearedFields[todo.FieldCategoryID] = struct{}{} } // CategoryCleared reports if the "category" edge to the Category entity was cleared. diff --git a/entgql/internal/todo/ent/onetomany/where.go b/entgql/internal/todo/ent/onetomany/where.go index 0a90bb964..70e8ffcaf 100644 --- a/entgql/internal/todo/ent/onetomany/where.go +++ b/entgql/internal/todo/ent/onetomany/where.go @@ -300,32 +300,15 @@ func HasChildrenWith(preds ...predicate.OneToMany) predicate.OneToMany { // And groups predicates with the AND operator between them. func And(predicates ...predicate.OneToMany) predicate.OneToMany { - return predicate.OneToMany(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.OneToMany(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.OneToMany) predicate.OneToMany { - return predicate.OneToMany(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.OneToMany(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.OneToMany) predicate.OneToMany { - return predicate.OneToMany(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.OneToMany(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/onetomany_create.go b/entgql/internal/todo/ent/onetomany_create.go index 01e9000ba..db7fd449b 100644 --- a/entgql/internal/todo/ent/onetomany_create.go +++ b/entgql/internal/todo/ent/onetomany_create.go @@ -94,7 +94,7 @@ func (otmc *OneToManyCreate) Mutation() *OneToManyMutation { // Save creates the OneToMany in the database. func (otmc *OneToManyCreate) Save(ctx context.Context) (*OneToMany, error) { - return withHooks[*OneToMany, OneToManyMutation](ctx, otmc.sqlSave, otmc.mutation, otmc.hooks) + return withHooks(ctx, otmc.sqlSave, otmc.mutation, otmc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -202,11 +202,15 @@ func (otmc *OneToManyCreate) createSpec() (*OneToMany, *sqlgraph.CreateSpec) { // OneToManyCreateBulk is the builder for creating many OneToMany entities in bulk. type OneToManyCreateBulk struct { config + err error builders []*OneToManyCreate } // Save creates the OneToMany entities in the database. func (otmcb *OneToManyCreateBulk) Save(ctx context.Context) ([]*OneToMany, error) { + if otmcb.err != nil { + return nil, otmcb.err + } specs := make([]*sqlgraph.CreateSpec, len(otmcb.builders)) nodes := make([]*OneToMany, len(otmcb.builders)) mutators := make([]Mutator, len(otmcb.builders)) diff --git a/entgql/internal/todo/ent/onetomany_delete.go b/entgql/internal/todo/ent/onetomany_delete.go index 2f80575f1..a4a6ead7f 100644 --- a/entgql/internal/todo/ent/onetomany_delete.go +++ b/entgql/internal/todo/ent/onetomany_delete.go @@ -41,7 +41,7 @@ func (otmd *OneToManyDelete) Where(ps ...predicate.OneToMany) *OneToManyDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (otmd *OneToManyDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, OneToManyMutation](ctx, otmd.sqlExec, otmd.mutation, otmd.hooks) + return withHooks(ctx, otmd.sqlExec, otmd.mutation, otmd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/onetomany_update.go b/entgql/internal/todo/ent/onetomany_update.go index 808fad1e6..302b2e42f 100644 --- a/entgql/internal/todo/ent/onetomany_update.go +++ b/entgql/internal/todo/ent/onetomany_update.go @@ -48,6 +48,14 @@ func (otmu *OneToManyUpdate) SetName(s string) *OneToManyUpdate { return otmu } +// SetNillableName sets the "name" field if the given value is not nil. +func (otmu *OneToManyUpdate) SetNillableName(s *string) *OneToManyUpdate { + if s != nil { + otmu.SetName(*s) + } + return otmu +} + // SetField2 sets the "field2" field. func (otmu *OneToManyUpdate) SetField2(s string) *OneToManyUpdate { otmu.mutation.SetField2(s) @@ -142,7 +150,7 @@ func (otmu *OneToManyUpdate) RemoveChildren(o ...*OneToMany) *OneToManyUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (otmu *OneToManyUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, OneToManyMutation](ctx, otmu.sqlSave, otmu.mutation, otmu.hooks) + return withHooks(ctx, otmu.sqlSave, otmu.mutation, otmu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -306,6 +314,14 @@ func (otmuo *OneToManyUpdateOne) SetName(s string) *OneToManyUpdateOne { return otmuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (otmuo *OneToManyUpdateOne) SetNillableName(s *string) *OneToManyUpdateOne { + if s != nil { + otmuo.SetName(*s) + } + return otmuo +} + // SetField2 sets the "field2" field. func (otmuo *OneToManyUpdateOne) SetField2(s string) *OneToManyUpdateOne { otmuo.mutation.SetField2(s) @@ -413,7 +429,7 @@ func (otmuo *OneToManyUpdateOne) Select(field string, fields ...string) *OneToMa // Save executes the query and returns the updated OneToMany entity. func (otmuo *OneToManyUpdateOne) Save(ctx context.Context) (*OneToMany, error) { - return withHooks[*OneToMany, OneToManyMutation](ctx, otmuo.sqlSave, otmuo.mutation, otmuo.hooks) + return withHooks(ctx, otmuo.sqlSave, otmuo.mutation, otmuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/project/where.go b/entgql/internal/todo/ent/project/where.go index f775ae331..7d816da36 100644 --- a/entgql/internal/todo/ent/project/where.go +++ b/entgql/internal/todo/ent/project/where.go @@ -92,32 +92,15 @@ func HasTodosWith(preds ...predicate.Todo) predicate.Project { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Project) predicate.Project { - return predicate.Project(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Project(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Project) predicate.Project { - return predicate.Project(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Project(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Project) predicate.Project { - return predicate.Project(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Project(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/project_create.go b/entgql/internal/todo/ent/project_create.go index 161e62dc2..9fdb5d49c 100644 --- a/entgql/internal/todo/ent/project_create.go +++ b/entgql/internal/todo/ent/project_create.go @@ -55,7 +55,7 @@ func (pc *ProjectCreate) Mutation() *ProjectMutation { // Save creates the Project in the database. func (pc *ProjectCreate) Save(ctx context.Context) (*Project, error) { - return withHooks[*Project, ProjectMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -130,11 +130,15 @@ func (pc *ProjectCreate) createSpec() (*Project, *sqlgraph.CreateSpec) { // ProjectCreateBulk is the builder for creating many Project entities in bulk. type ProjectCreateBulk struct { config + err error builders []*ProjectCreate } // Save creates the Project entities in the database. func (pcb *ProjectCreateBulk) Save(ctx context.Context) ([]*Project, error) { + if pcb.err != nil { + return nil, pcb.err + } specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) nodes := make([]*Project, len(pcb.builders)) mutators := make([]Mutator, len(pcb.builders)) diff --git a/entgql/internal/todo/ent/project_delete.go b/entgql/internal/todo/ent/project_delete.go index b1c353ed7..747400ef9 100644 --- a/entgql/internal/todo/ent/project_delete.go +++ b/entgql/internal/todo/ent/project_delete.go @@ -41,7 +41,7 @@ func (pd *ProjectDelete) Where(ps ...predicate.Project) *ProjectDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *ProjectDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, ProjectMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/project_update.go b/entgql/internal/todo/ent/project_update.go index e8f2c3319..ce4ac7ce7 100644 --- a/entgql/internal/todo/ent/project_update.go +++ b/entgql/internal/todo/ent/project_update.go @@ -86,7 +86,7 @@ func (pu *ProjectUpdate) RemoveTodos(t ...*Todo) *ProjectUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *ProjectUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, ProjectMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -249,7 +249,7 @@ func (puo *ProjectUpdateOne) Select(field string, fields ...string) *ProjectUpda // Save executes the query and returns the updated Project entity. func (puo *ProjectUpdateOne) Save(ctx context.Context) (*Project, error) { - return withHooks[*Project, ProjectMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/runtime/runtime.go b/entgql/internal/todo/ent/runtime/runtime.go index e0c02312c..e60ad3f1f 100644 --- a/entgql/internal/todo/ent/runtime/runtime.go +++ b/entgql/internal/todo/ent/runtime/runtime.go @@ -19,6 +19,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entgql/internal/todo/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entgql/internal/todo/ent/todo/where.go b/entgql/internal/todo/ent/todo/where.go index 4167e0c88..70eba5527 100644 --- a/entgql/internal/todo/ent/todo/where.go +++ b/entgql/internal/todo/ent/todo/where.go @@ -463,32 +463,15 @@ func HasSecretWith(preds ...predicate.VerySecret) predicate.Todo { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Todo(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/todo_create.go b/entgql/internal/todo/ent/todo_create.go index a7fc58841..8486dbe26 100644 --- a/entgql/internal/todo/ent/todo_create.go +++ b/entgql/internal/todo/ent/todo_create.go @@ -181,7 +181,7 @@ func (tc *TodoCreate) Mutation() *TodoMutation { // Save creates the Todo in the database. func (tc *TodoCreate) Save(ctx context.Context) (*Todo, error) { tc.defaults() - return withHooks[*Todo, TodoMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -373,11 +373,15 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { // TodoCreateBulk is the builder for creating many Todo entities in bulk. type TodoCreateBulk struct { config + err error builders []*TodoCreate } // Save creates the Todo entities in the database. func (tcb *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Todo, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) diff --git a/entgql/internal/todo/ent/todo_delete.go b/entgql/internal/todo/ent/todo_delete.go index 9bc05829e..51b0fb756 100644 --- a/entgql/internal/todo/ent/todo_delete.go +++ b/entgql/internal/todo/ent/todo_delete.go @@ -41,7 +41,7 @@ func (td *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TodoDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/todo_update.go b/entgql/internal/todo/ent/todo_update.go index 0f8478c68..c1dacd8c0 100644 --- a/entgql/internal/todo/ent/todo_update.go +++ b/entgql/internal/todo/ent/todo_update.go @@ -51,6 +51,14 @@ func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate { return tu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableStatus(t *todo.Status) *TodoUpdate { + if t != nil { + tu.SetStatus(*t) + } + return tu +} + // SetPriority sets the "priority" field. func (tu *TodoUpdate) SetPriority(i int) *TodoUpdate { tu.mutation.ResetPriority() @@ -78,6 +86,14 @@ func (tu *TodoUpdate) SetText(s string) *TodoUpdate { return tu } +// SetNillableText sets the "text" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { + if s != nil { + tu.SetText(*s) + } + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -231,7 +247,7 @@ func (tu *TodoUpdate) ClearSecret() *TodoUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TodoUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -466,6 +482,14 @@ func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne { return tuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableStatus(t *todo.Status) *TodoUpdateOne { + if t != nil { + tuo.SetStatus(*t) + } + return tuo +} + // SetPriority sets the "priority" field. func (tuo *TodoUpdateOne) SetPriority(i int) *TodoUpdateOne { tuo.mutation.ResetPriority() @@ -493,6 +517,14 @@ func (tuo *TodoUpdateOne) SetText(s string) *TodoUpdateOne { return tuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetText(*s) + } + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -659,7 +691,7 @@ func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne // Save executes the query and returns the updated Todo entity. func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { - return withHooks[*Todo, TodoMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/user/where.go b/entgql/internal/todo/ent/user/where.go index fb40d2876..2c9323b52 100644 --- a/entgql/internal/todo/ent/user/where.go +++ b/entgql/internal/todo/ent/user/where.go @@ -344,32 +344,15 @@ func HasFriendshipsWith(preds ...predicate.Friendship) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/user_create.go b/entgql/internal/todo/ent/user_create.go index 2f35d7a70..51ef55403 100644 --- a/entgql/internal/todo/ent/user_create.go +++ b/entgql/internal/todo/ent/user_create.go @@ -143,7 +143,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { uc.defaults() - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -295,11 +295,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entgql/internal/todo/ent/user_delete.go b/entgql/internal/todo/ent/user_delete.go index 0aa279023..5cd6bc9e1 100644 --- a/entgql/internal/todo/ent/user_delete.go +++ b/entgql/internal/todo/ent/user_delete.go @@ -41,7 +41,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/user_update.go b/entgql/internal/todo/ent/user_update.go index 97dd228e2..b834e126d 100644 --- a/entgql/internal/todo/ent/user_update.go +++ b/entgql/internal/todo/ent/user_update.go @@ -226,7 +226,7 @@ func (uu *UserUpdate) RemoveFriendships(f ...*Friendship) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -650,7 +650,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/verysecret/where.go b/entgql/internal/todo/ent/verysecret/where.go index f98780abd..086916dc6 100644 --- a/entgql/internal/todo/ent/verysecret/where.go +++ b/entgql/internal/todo/ent/verysecret/where.go @@ -138,32 +138,15 @@ func PasswordContainsFold(v string) predicate.VerySecret { // And groups predicates with the AND operator between them. func And(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.VerySecret(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/verysecret_create.go b/entgql/internal/todo/ent/verysecret_create.go index 418edc5b7..6e9ead9bb 100644 --- a/entgql/internal/todo/ent/verysecret_create.go +++ b/entgql/internal/todo/ent/verysecret_create.go @@ -46,7 +46,7 @@ func (vsc *VerySecretCreate) Mutation() *VerySecretMutation { // Save creates the VerySecret in the database. func (vsc *VerySecretCreate) Save(ctx context.Context) (*VerySecret, error) { - return withHooks[*VerySecret, VerySecretMutation](ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) + return withHooks(ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -112,11 +112,15 @@ func (vsc *VerySecretCreate) createSpec() (*VerySecret, *sqlgraph.CreateSpec) { // VerySecretCreateBulk is the builder for creating many VerySecret entities in bulk. type VerySecretCreateBulk struct { config + err error builders []*VerySecretCreate } // Save creates the VerySecret entities in the database. func (vscb *VerySecretCreateBulk) Save(ctx context.Context) ([]*VerySecret, error) { + if vscb.err != nil { + return nil, vscb.err + } specs := make([]*sqlgraph.CreateSpec, len(vscb.builders)) nodes := make([]*VerySecret, len(vscb.builders)) mutators := make([]Mutator, len(vscb.builders)) diff --git a/entgql/internal/todo/ent/verysecret_delete.go b/entgql/internal/todo/ent/verysecret_delete.go index 11edb920d..24033ae49 100644 --- a/entgql/internal/todo/ent/verysecret_delete.go +++ b/entgql/internal/todo/ent/verysecret_delete.go @@ -41,7 +41,7 @@ func (vsd *VerySecretDelete) Where(ps ...predicate.VerySecret) *VerySecretDelete // Exec executes the deletion query and returns how many vertices were deleted. func (vsd *VerySecretDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) + return withHooks(ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/verysecret_update.go b/entgql/internal/todo/ent/verysecret_update.go index 24680bc76..fe7c7e140 100644 --- a/entgql/internal/todo/ent/verysecret_update.go +++ b/entgql/internal/todo/ent/verysecret_update.go @@ -48,6 +48,14 @@ func (vsu *VerySecretUpdate) SetPassword(s string) *VerySecretUpdate { return vsu } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsu *VerySecretUpdate) SetNillablePassword(s *string) *VerySecretUpdate { + if s != nil { + vsu.SetPassword(*s) + } + return vsu +} + // Mutation returns the VerySecretMutation object of the builder. func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { return vsu.mutation @@ -55,7 +63,7 @@ func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (vsu *VerySecretUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) + return withHooks(ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -126,6 +134,14 @@ func (vsuo *VerySecretUpdateOne) SetPassword(s string) *VerySecretUpdateOne { return vsuo } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsuo *VerySecretUpdateOne) SetNillablePassword(s *string) *VerySecretUpdateOne { + if s != nil { + vsuo.SetPassword(*s) + } + return vsuo +} + // Mutation returns the VerySecretMutation object of the builder. func (vsuo *VerySecretUpdateOne) Mutation() *VerySecretMutation { return vsuo.mutation @@ -146,7 +162,7 @@ func (vsuo *VerySecretUpdateOne) Select(field string, fields ...string) *VerySec // Save executes the query and returns the updated VerySecret entity. func (vsuo *VerySecretUpdateOne) Save(ctx context.Context) (*VerySecret, error) { - return withHooks[*VerySecret, VerySecretMutation](ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) + return withHooks(ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/workspace/where.go b/entgql/internal/todo/ent/workspace/where.go index 2fe98bfe3..8de62ab15 100644 --- a/entgql/internal/todo/ent/workspace/where.go +++ b/entgql/internal/todo/ent/workspace/where.go @@ -138,32 +138,15 @@ func NameContainsFold(v string) predicate.Workspace { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Workspace) predicate.Workspace { - return predicate.Workspace(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Workspace(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Workspace) predicate.Workspace { - return predicate.Workspace(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Workspace(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Workspace) predicate.Workspace { - return predicate.Workspace(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Workspace(sql.NotPredicates(p)) } diff --git a/entgql/internal/todo/ent/workspace_create.go b/entgql/internal/todo/ent/workspace_create.go index b86903dac..bb49f4103 100644 --- a/entgql/internal/todo/ent/workspace_create.go +++ b/entgql/internal/todo/ent/workspace_create.go @@ -46,7 +46,7 @@ func (wc *WorkspaceCreate) Mutation() *WorkspaceMutation { // Save creates the Workspace in the database. func (wc *WorkspaceCreate) Save(ctx context.Context) (*Workspace, error) { - return withHooks[*Workspace, WorkspaceMutation](ctx, wc.sqlSave, wc.mutation, wc.hooks) + return withHooks(ctx, wc.sqlSave, wc.mutation, wc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -112,11 +112,15 @@ func (wc *WorkspaceCreate) createSpec() (*Workspace, *sqlgraph.CreateSpec) { // WorkspaceCreateBulk is the builder for creating many Workspace entities in bulk. type WorkspaceCreateBulk struct { config + err error builders []*WorkspaceCreate } // Save creates the Workspace entities in the database. func (wcb *WorkspaceCreateBulk) Save(ctx context.Context) ([]*Workspace, error) { + if wcb.err != nil { + return nil, wcb.err + } specs := make([]*sqlgraph.CreateSpec, len(wcb.builders)) nodes := make([]*Workspace, len(wcb.builders)) mutators := make([]Mutator, len(wcb.builders)) diff --git a/entgql/internal/todo/ent/workspace_delete.go b/entgql/internal/todo/ent/workspace_delete.go index ebec70e65..8abf87c6e 100644 --- a/entgql/internal/todo/ent/workspace_delete.go +++ b/entgql/internal/todo/ent/workspace_delete.go @@ -41,7 +41,7 @@ func (wd *WorkspaceDelete) Where(ps ...predicate.Workspace) *WorkspaceDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (wd *WorkspaceDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, WorkspaceMutation](ctx, wd.sqlExec, wd.mutation, wd.hooks) + return withHooks(ctx, wd.sqlExec, wd.mutation, wd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todo/ent/workspace_update.go b/entgql/internal/todo/ent/workspace_update.go index 6e7009b6d..92325ed73 100644 --- a/entgql/internal/todo/ent/workspace_update.go +++ b/entgql/internal/todo/ent/workspace_update.go @@ -48,6 +48,14 @@ func (wu *WorkspaceUpdate) SetName(s string) *WorkspaceUpdate { return wu } +// SetNillableName sets the "name" field if the given value is not nil. +func (wu *WorkspaceUpdate) SetNillableName(s *string) *WorkspaceUpdate { + if s != nil { + wu.SetName(*s) + } + return wu +} + // Mutation returns the WorkspaceMutation object of the builder. func (wu *WorkspaceUpdate) Mutation() *WorkspaceMutation { return wu.mutation @@ -55,7 +63,7 @@ func (wu *WorkspaceUpdate) Mutation() *WorkspaceMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (wu *WorkspaceUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, WorkspaceMutation](ctx, wu.sqlSave, wu.mutation, wu.hooks) + return withHooks(ctx, wu.sqlSave, wu.mutation, wu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -126,6 +134,14 @@ func (wuo *WorkspaceUpdateOne) SetName(s string) *WorkspaceUpdateOne { return wuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (wuo *WorkspaceUpdateOne) SetNillableName(s *string) *WorkspaceUpdateOne { + if s != nil { + wuo.SetName(*s) + } + return wuo +} + // Mutation returns the WorkspaceMutation object of the builder. func (wuo *WorkspaceUpdateOne) Mutation() *WorkspaceMutation { return wuo.mutation @@ -146,7 +162,7 @@ func (wuo *WorkspaceUpdateOne) Select(field string, fields ...string) *Workspace // Save executes the query and returns the updated Workspace entity. func (wuo *WorkspaceUpdateOne) Save(ctx context.Context) (*Workspace, error) { - return withHooks[*Workspace, WorkspaceMutation](ctx, wuo.sqlSave, wuo.mutation, wuo.hooks) + return withHooks(ctx, wuo.sqlSave, wuo.mutation, wuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todo/server/server.go b/entgql/internal/todo/server/server.go index 5d74013d5..09f43e05f 100644 --- a/entgql/internal/todo/server/server.go +++ b/entgql/internal/todo/server/server.go @@ -16,6 +16,7 @@ package main import ( "context" "net/http" + "time" "entgo.io/contrib/entgql" "entgo.io/contrib/entgql/internal/todo" @@ -65,7 +66,11 @@ func main() { http.Handle("/query", srv) log.Info("listening on", zap.String("address", cli.Addr)) - if err := http.ListenAndServe(cli.Addr, nil); err != nil { + server := &http.Server{ + Addr: cli.Addr, + ReadHeaderTimeout: 30 * time.Second, + } + if err := server.ListenAndServe(); err != nil { log.Error("http server terminated", zap.Error(err)) } } diff --git a/entgql/internal/todofed/ent/category/where.go b/entgql/internal/todofed/ent/category/where.go index 015f99487..3f9525288 100644 --- a/entgql/internal/todofed/ent/category/where.go +++ b/entgql/internal/todofed/ent/category/where.go @@ -375,32 +375,15 @@ func HasTodosWith(preds ...predicate.Todo) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entgql/internal/todofed/ent/category_create.go b/entgql/internal/todofed/ent/category_create.go index 7c4253f65..61e4b9735 100644 --- a/entgql/internal/todofed/ent/category_create.go +++ b/entgql/internal/todofed/ent/category_create.go @@ -110,7 +110,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -225,11 +225,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entgql/internal/todofed/ent/category_delete.go b/entgql/internal/todofed/ent/category_delete.go index ffafddbb2..75b7a41d6 100644 --- a/entgql/internal/todofed/ent/category_delete.go +++ b/entgql/internal/todofed/ent/category_delete.go @@ -41,7 +41,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todofed/ent/category_update.go b/entgql/internal/todofed/ent/category_update.go index 9edf9a0a4..05d1c57c9 100644 --- a/entgql/internal/todofed/ent/category_update.go +++ b/entgql/internal/todofed/ent/category_update.go @@ -51,12 +51,28 @@ func (cu *CategoryUpdate) SetText(s string) *CategoryUpdate { return cu } +// SetNillableText sets the "text" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableText(s *string) *CategoryUpdate { + if s != nil { + cu.SetText(*s) + } + return cu +} + // SetStatus sets the "status" field. func (cu *CategoryUpdate) SetStatus(c category.Status) *CategoryUpdate { cu.mutation.SetStatus(c) return cu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableStatus(c *category.Status) *CategoryUpdate { + if c != nil { + cu.SetStatus(*c) + } + return cu +} + // SetConfig sets the "config" field. func (cu *CategoryUpdate) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdate { cu.mutation.SetConfig(sc) @@ -184,7 +200,7 @@ func (cu *CategoryUpdate) RemoveTodos(t ...*Todo) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -348,12 +364,28 @@ func (cuo *CategoryUpdateOne) SetText(s string) *CategoryUpdateOne { return cuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableText(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetText(*s) + } + return cuo +} + // SetStatus sets the "status" field. func (cuo *CategoryUpdateOne) SetStatus(c category.Status) *CategoryUpdateOne { cuo.mutation.SetStatus(c) return cuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableStatus(c *category.Status) *CategoryUpdateOne { + if c != nil { + cuo.SetStatus(*c) + } + return cuo +} + // SetConfig sets the "config" field. func (cuo *CategoryUpdateOne) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdateOne { cuo.mutation.SetConfig(sc) @@ -494,7 +526,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todofed/ent/client.go b/entgql/internal/todofed/ent/client.go index 076b18a88..a9f2dfa1a 100644 --- a/entgql/internal/todofed/ent/client.go +++ b/entgql/internal/todofed/ent/client.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entgql/internal/todofed/ent/migrate" "entgo.io/ent" @@ -129,11 +130,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -257,6 +261,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -391,6 +410,21 @@ func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk { return &TodoCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TodoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TodoCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Todo. func (c *TodoClient) Update() *TodoUpdate { mutation := newTodoMutation(c.config, OpUpdate) @@ -573,6 +607,21 @@ func (c *VerySecretClient) CreateBulk(builders ...*VerySecretCreate) *VerySecret return &VerySecretCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *VerySecretClient) MapCreateBulk(slice any, setFunc func(*VerySecretCreate, int)) *VerySecretCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &VerySecretCreateBulk{err: fmt.Errorf("calling to VerySecretClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*VerySecretCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &VerySecretCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for VerySecret. func (c *VerySecretClient) Update() *VerySecretUpdate { mutation := newVerySecretMutation(c.config, OpUpdate) diff --git a/entgql/internal/todofed/ent/runtime/runtime.go b/entgql/internal/todofed/ent/runtime/runtime.go index 37df9b5f1..730f41d97 100644 --- a/entgql/internal/todofed/ent/runtime/runtime.go +++ b/entgql/internal/todofed/ent/runtime/runtime.go @@ -19,6 +19,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entgql/internal/todofed/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entgql/internal/todofed/ent/todo/where.go b/entgql/internal/todofed/ent/todo/where.go index b7a831a13..95e80ce42 100644 --- a/entgql/internal/todofed/ent/todo/where.go +++ b/entgql/internal/todofed/ent/todo/where.go @@ -398,32 +398,15 @@ func HasSecretWith(preds ...predicate.VerySecret) predicate.Todo { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Todo(sql.NotPredicates(p)) } diff --git a/entgql/internal/todofed/ent/todo_create.go b/entgql/internal/todofed/ent/todo_create.go index 787711b33..dfe9864b3 100644 --- a/entgql/internal/todofed/ent/todo_create.go +++ b/entgql/internal/todofed/ent/todo_create.go @@ -162,7 +162,7 @@ func (tc *TodoCreate) Mutation() *TodoMutation { // Save creates the Todo in the database. func (tc *TodoCreate) Save(ctx context.Context) (*Todo, error) { tc.defaults() - return withHooks[*Todo, TodoMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -342,11 +342,15 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { // TodoCreateBulk is the builder for creating many Todo entities in bulk. type TodoCreateBulk struct { config + err error builders []*TodoCreate } // Save creates the Todo entities in the database. func (tcb *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Todo, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) diff --git a/entgql/internal/todofed/ent/todo_delete.go b/entgql/internal/todofed/ent/todo_delete.go index d1441ca41..ed37209d2 100644 --- a/entgql/internal/todofed/ent/todo_delete.go +++ b/entgql/internal/todofed/ent/todo_delete.go @@ -41,7 +41,7 @@ func (td *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TodoDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todofed/ent/todo_update.go b/entgql/internal/todofed/ent/todo_update.go index 5c507d243..148ec3f60 100644 --- a/entgql/internal/todofed/ent/todo_update.go +++ b/entgql/internal/todofed/ent/todo_update.go @@ -49,6 +49,14 @@ func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate { return tu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableStatus(t *todo.Status) *TodoUpdate { + if t != nil { + tu.SetStatus(*t) + } + return tu +} + // SetPriority sets the "priority" field. func (tu *TodoUpdate) SetPriority(i int) *TodoUpdate { tu.mutation.ResetPriority() @@ -76,6 +84,14 @@ func (tu *TodoUpdate) SetText(s string) *TodoUpdate { return tu } +// SetNillableText sets the "text" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { + if s != nil { + tu.SetText(*s) + } + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -206,7 +222,7 @@ func (tu *TodoUpdate) ClearSecret() *TodoUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TodoUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -434,6 +450,14 @@ func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne { return tuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableStatus(t *todo.Status) *TodoUpdateOne { + if t != nil { + tuo.SetStatus(*t) + } + return tuo +} + // SetPriority sets the "priority" field. func (tuo *TodoUpdateOne) SetPriority(i int) *TodoUpdateOne { tuo.mutation.ResetPriority() @@ -461,6 +485,14 @@ func (tuo *TodoUpdateOne) SetText(s string) *TodoUpdateOne { return tuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetText(*s) + } + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -604,7 +636,7 @@ func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne // Save executes the query and returns the updated Todo entity. func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { - return withHooks[*Todo, TodoMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todofed/ent/verysecret/where.go b/entgql/internal/todofed/ent/verysecret/where.go index 6db4bfabe..04d1441f7 100644 --- a/entgql/internal/todofed/ent/verysecret/where.go +++ b/entgql/internal/todofed/ent/verysecret/where.go @@ -138,32 +138,15 @@ func PasswordContainsFold(v string) predicate.VerySecret { // And groups predicates with the AND operator between them. func And(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.VerySecret(sql.NotPredicates(p)) } diff --git a/entgql/internal/todofed/ent/verysecret_create.go b/entgql/internal/todofed/ent/verysecret_create.go index cc8236027..ecb18239a 100644 --- a/entgql/internal/todofed/ent/verysecret_create.go +++ b/entgql/internal/todofed/ent/verysecret_create.go @@ -46,7 +46,7 @@ func (vsc *VerySecretCreate) Mutation() *VerySecretMutation { // Save creates the VerySecret in the database. func (vsc *VerySecretCreate) Save(ctx context.Context) (*VerySecret, error) { - return withHooks[*VerySecret, VerySecretMutation](ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) + return withHooks(ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -112,11 +112,15 @@ func (vsc *VerySecretCreate) createSpec() (*VerySecret, *sqlgraph.CreateSpec) { // VerySecretCreateBulk is the builder for creating many VerySecret entities in bulk. type VerySecretCreateBulk struct { config + err error builders []*VerySecretCreate } // Save creates the VerySecret entities in the database. func (vscb *VerySecretCreateBulk) Save(ctx context.Context) ([]*VerySecret, error) { + if vscb.err != nil { + return nil, vscb.err + } specs := make([]*sqlgraph.CreateSpec, len(vscb.builders)) nodes := make([]*VerySecret, len(vscb.builders)) mutators := make([]Mutator, len(vscb.builders)) diff --git a/entgql/internal/todofed/ent/verysecret_delete.go b/entgql/internal/todofed/ent/verysecret_delete.go index d9ed1594f..cac66d33b 100644 --- a/entgql/internal/todofed/ent/verysecret_delete.go +++ b/entgql/internal/todofed/ent/verysecret_delete.go @@ -41,7 +41,7 @@ func (vsd *VerySecretDelete) Where(ps ...predicate.VerySecret) *VerySecretDelete // Exec executes the deletion query and returns how many vertices were deleted. func (vsd *VerySecretDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) + return withHooks(ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todofed/ent/verysecret_update.go b/entgql/internal/todofed/ent/verysecret_update.go index 954001a16..7446d8852 100644 --- a/entgql/internal/todofed/ent/verysecret_update.go +++ b/entgql/internal/todofed/ent/verysecret_update.go @@ -47,6 +47,14 @@ func (vsu *VerySecretUpdate) SetPassword(s string) *VerySecretUpdate { return vsu } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsu *VerySecretUpdate) SetNillablePassword(s *string) *VerySecretUpdate { + if s != nil { + vsu.SetPassword(*s) + } + return vsu +} + // Mutation returns the VerySecretMutation object of the builder. func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { return vsu.mutation @@ -54,7 +62,7 @@ func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (vsu *VerySecretUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) + return withHooks(ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -117,6 +125,14 @@ func (vsuo *VerySecretUpdateOne) SetPassword(s string) *VerySecretUpdateOne { return vsuo } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsuo *VerySecretUpdateOne) SetNillablePassword(s *string) *VerySecretUpdateOne { + if s != nil { + vsuo.SetPassword(*s) + } + return vsuo +} + // Mutation returns the VerySecretMutation object of the builder. func (vsuo *VerySecretUpdateOne) Mutation() *VerySecretMutation { return vsuo.mutation @@ -137,7 +153,7 @@ func (vsuo *VerySecretUpdateOne) Select(field string, fields ...string) *VerySec // Save executes the query and returns the updated VerySecret entity. func (vsuo *VerySecretUpdateOne) Save(ctx context.Context) (*VerySecret, error) { - return withHooks[*VerySecret, VerySecretMutation](ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) + return withHooks(ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todofed/server/server.go b/entgql/internal/todofed/server/server.go index ceabb985d..503f8ec53 100644 --- a/entgql/internal/todofed/server/server.go +++ b/entgql/internal/todofed/server/server.go @@ -16,6 +16,7 @@ package main import ( "context" "net/http" + "time" "entgo.io/contrib/entgql" "entgo.io/contrib/entgql/internal/todofed" @@ -65,7 +66,11 @@ func main() { http.Handle("/query", srv) log.Info("listening on", zap.String("address", cli.Addr)) - if err := http.ListenAndServe(cli.Addr, nil); err != nil { + server := &http.Server{ + Addr: cli.Addr, + ReadHeaderTimeout: 30 * time.Second, + } + if err := server.ListenAndServe(); err != nil { log.Error("http server terminated", zap.Error(err)) } } diff --git a/entgql/internal/todogotype/ent/billproduct/where.go b/entgql/internal/todogotype/ent/billproduct/where.go index a26c84f74..83ea01388 100644 --- a/entgql/internal/todogotype/ent/billproduct/where.go +++ b/entgql/internal/todogotype/ent/billproduct/where.go @@ -263,32 +263,15 @@ func QuantityLTE(v uint64) predicate.BillProduct { // And groups predicates with the AND operator between them. func And(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.BillProduct(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/billproduct_create.go b/entgql/internal/todogotype/ent/billproduct_create.go index 1a5f75a50..8d5fcf998 100644 --- a/entgql/internal/todogotype/ent/billproduct_create.go +++ b/entgql/internal/todogotype/ent/billproduct_create.go @@ -58,7 +58,7 @@ func (bpc *BillProductCreate) Mutation() *BillProductMutation { // Save creates the BillProduct in the database. func (bpc *BillProductCreate) Save(ctx context.Context) (*BillProduct, error) { - return withHooks[*BillProduct, BillProductMutation](ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) + return withHooks(ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -143,11 +143,15 @@ func (bpc *BillProductCreate) createSpec() (*BillProduct, *sqlgraph.CreateSpec) // BillProductCreateBulk is the builder for creating many BillProduct entities in bulk. type BillProductCreateBulk struct { config + err error builders []*BillProductCreate } // Save creates the BillProduct entities in the database. func (bpcb *BillProductCreateBulk) Save(ctx context.Context) ([]*BillProduct, error) { + if bpcb.err != nil { + return nil, bpcb.err + } specs := make([]*sqlgraph.CreateSpec, len(bpcb.builders)) nodes := make([]*BillProduct, len(bpcb.builders)) mutators := make([]Mutator, len(bpcb.builders)) diff --git a/entgql/internal/todogotype/ent/billproduct_delete.go b/entgql/internal/todogotype/ent/billproduct_delete.go index ca51e2179..9b3cdbce8 100644 --- a/entgql/internal/todogotype/ent/billproduct_delete.go +++ b/entgql/internal/todogotype/ent/billproduct_delete.go @@ -41,7 +41,7 @@ func (bpd *BillProductDelete) Where(ps ...predicate.BillProduct) *BillProductDel // Exec executes the deletion query and returns how many vertices were deleted. func (bpd *BillProductDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) + return withHooks(ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/billproduct_update.go b/entgql/internal/todogotype/ent/billproduct_update.go index 1542e98ad..13a5dad97 100644 --- a/entgql/internal/todogotype/ent/billproduct_update.go +++ b/entgql/internal/todogotype/ent/billproduct_update.go @@ -47,12 +47,28 @@ func (bpu *BillProductUpdate) SetName(s string) *BillProductUpdate { return bpu } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableName(s *string) *BillProductUpdate { + if s != nil { + bpu.SetName(*s) + } + return bpu +} + // SetSku sets the "sku" field. func (bpu *BillProductUpdate) SetSku(s string) *BillProductUpdate { bpu.mutation.SetSku(s) return bpu } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableSku(s *string) *BillProductUpdate { + if s != nil { + bpu.SetSku(*s) + } + return bpu +} + // SetQuantity sets the "quantity" field. func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { bpu.mutation.ResetQuantity() @@ -60,6 +76,14 @@ func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { return bpu } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableQuantity(u *uint64) *BillProductUpdate { + if u != nil { + bpu.SetQuantity(*u) + } + return bpu +} + // AddQuantity adds u to the "quantity" field. func (bpu *BillProductUpdate) AddQuantity(u int64) *BillProductUpdate { bpu.mutation.AddQuantity(u) @@ -73,7 +97,7 @@ func (bpu *BillProductUpdate) Mutation() *BillProductMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (bpu *BillProductUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) + return withHooks(ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -145,12 +169,28 @@ func (bpuo *BillProductUpdateOne) SetName(s string) *BillProductUpdateOne { return bpuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableName(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetName(*s) + } + return bpuo +} + // SetSku sets the "sku" field. func (bpuo *BillProductUpdateOne) SetSku(s string) *BillProductUpdateOne { bpuo.mutation.SetSku(s) return bpuo } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableSku(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetSku(*s) + } + return bpuo +} + // SetQuantity sets the "quantity" field. func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { bpuo.mutation.ResetQuantity() @@ -158,6 +198,14 @@ func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { return bpuo } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableQuantity(u *uint64) *BillProductUpdateOne { + if u != nil { + bpuo.SetQuantity(*u) + } + return bpuo +} + // AddQuantity adds u to the "quantity" field. func (bpuo *BillProductUpdateOne) AddQuantity(u int64) *BillProductUpdateOne { bpuo.mutation.AddQuantity(u) @@ -184,7 +232,7 @@ func (bpuo *BillProductUpdateOne) Select(field string, fields ...string) *BillPr // Save executes the query and returns the updated BillProduct entity. func (bpuo *BillProductUpdateOne) Save(ctx context.Context) (*BillProduct, error) { - return withHooks[*BillProduct, BillProductMutation](ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) + return withHooks(ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/category/where.go b/entgql/internal/todogotype/ent/category/where.go index a14356e48..798148e92 100644 --- a/entgql/internal/todogotype/ent/category/where.go +++ b/entgql/internal/todogotype/ent/category/where.go @@ -409,32 +409,15 @@ func HasSubCategoriesWith(preds ...predicate.Category) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/category_create.go b/entgql/internal/todogotype/ent/category_create.go index 626be03e7..e013998ba 100644 --- a/entgql/internal/todogotype/ent/category_create.go +++ b/entgql/internal/todogotype/ent/category_create.go @@ -147,7 +147,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { cc.defaults() - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -299,11 +299,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entgql/internal/todogotype/ent/category_delete.go b/entgql/internal/todogotype/ent/category_delete.go index 482c2ba8e..df64e369e 100644 --- a/entgql/internal/todogotype/ent/category_delete.go +++ b/entgql/internal/todogotype/ent/category_delete.go @@ -41,7 +41,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/category_update.go b/entgql/internal/todogotype/ent/category_update.go index ea9cc21da..247b82930 100644 --- a/entgql/internal/todogotype/ent/category_update.go +++ b/entgql/internal/todogotype/ent/category_update.go @@ -52,12 +52,28 @@ func (cu *CategoryUpdate) SetText(s string) *CategoryUpdate { return cu } +// SetNillableText sets the "text" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableText(s *string) *CategoryUpdate { + if s != nil { + cu.SetText(*s) + } + return cu +} + // SetStatus sets the "status" field. func (cu *CategoryUpdate) SetStatus(c category.Status) *CategoryUpdate { cu.mutation.SetStatus(c) return cu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableStatus(c *category.Status) *CategoryUpdate { + if c != nil { + cu.SetStatus(*c) + } + return cu +} + // SetConfig sets the "config" field. func (cu *CategoryUpdate) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdate { cu.mutation.SetConfig(sc) @@ -233,7 +249,7 @@ func (cu *CategoryUpdate) RemoveSubCategories(c ...*Category) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -448,12 +464,28 @@ func (cuo *CategoryUpdateOne) SetText(s string) *CategoryUpdateOne { return cuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableText(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetText(*s) + } + return cuo +} + // SetStatus sets the "status" field. func (cuo *CategoryUpdateOne) SetStatus(c category.Status) *CategoryUpdateOne { cuo.mutation.SetStatus(c) return cuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableStatus(c *category.Status) *CategoryUpdateOne { + if c != nil { + cuo.SetStatus(*c) + } + return cuo +} + // SetConfig sets the "config" field. func (cuo *CategoryUpdateOne) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdateOne { cuo.mutation.SetConfig(sc) @@ -642,7 +674,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/client.go b/entgql/internal/todogotype/ent/client.go index 5e07a0a0c..30e82d3ba 100644 --- a/entgql/internal/todogotype/ent/client.go +++ b/entgql/internal/todogotype/ent/client.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entgql/internal/todogotype/ent/migrate" "entgo.io/contrib/entgql/internal/todogotype/ent/schema/bigintgql" @@ -149,11 +150,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -303,6 +307,21 @@ func (c *BillProductClient) CreateBulk(builders ...*BillProductCreate) *BillProd return &BillProductCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *BillProductClient) MapCreateBulk(slice any, setFunc func(*BillProductCreate, int)) *BillProductCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &BillProductCreateBulk{err: fmt.Errorf("calling to BillProductClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*BillProductCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &BillProductCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for BillProduct. func (c *BillProductClient) Update() *BillProductUpdate { mutation := newBillProductMutation(c.config, OpUpdate) @@ -421,6 +440,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -571,6 +605,21 @@ func (c *FriendshipClient) CreateBulk(builders ...*FriendshipCreate) *Friendship return &FriendshipCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *FriendshipClient) MapCreateBulk(slice any, setFunc func(*FriendshipCreate, int)) *FriendshipCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &FriendshipCreateBulk{err: fmt.Errorf("calling to FriendshipClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*FriendshipCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &FriendshipCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Friendship. func (c *FriendshipClient) Update() *FriendshipUpdate { mutation := newFriendshipMutation(c.config, OpUpdate) @@ -721,6 +770,21 @@ func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { return &GroupCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Group. func (c *GroupClient) Update() *GroupUpdate { mutation := newGroupMutation(c.config, OpUpdate) @@ -855,6 +919,21 @@ func (c *PetClient) CreateBulk(builders ...*PetCreate) *PetCreateBulk { return &PetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PetClient) MapCreateBulk(slice any, setFunc func(*PetCreate, int)) *PetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PetCreateBulk{err: fmt.Errorf("calling to PetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Pet. func (c *PetClient) Update() *PetUpdate { mutation := newPetMutation(c.config, OpUpdate) @@ -973,6 +1052,21 @@ func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk { return &TodoCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TodoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TodoCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Todo. func (c *TodoClient) Update() *TodoUpdate { mutation := newTodoMutation(c.config, OpUpdate) @@ -1155,6 +1249,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) @@ -1321,6 +1430,21 @@ func (c *VerySecretClient) CreateBulk(builders ...*VerySecretCreate) *VerySecret return &VerySecretCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *VerySecretClient) MapCreateBulk(slice any, setFunc func(*VerySecretCreate, int)) *VerySecretCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &VerySecretCreateBulk{err: fmt.Errorf("calling to VerySecretClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*VerySecretCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &VerySecretCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for VerySecret. func (c *VerySecretClient) Update() *VerySecretUpdate { mutation := newVerySecretMutation(c.config, OpUpdate) diff --git a/entgql/internal/todogotype/ent/friendship/where.go b/entgql/internal/todogotype/ent/friendship/where.go index 001178a2f..a68d840ae 100644 --- a/entgql/internal/todogotype/ent/friendship/where.go +++ b/entgql/internal/todogotype/ent/friendship/where.go @@ -312,32 +312,15 @@ func HasFriendWith(preds ...predicate.User) predicate.Friendship { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Friendship(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/friendship_create.go b/entgql/internal/todogotype/ent/friendship_create.go index 2fe0ac870..7badbd052 100644 --- a/entgql/internal/todogotype/ent/friendship_create.go +++ b/entgql/internal/todogotype/ent/friendship_create.go @@ -79,7 +79,7 @@ func (fc *FriendshipCreate) Mutation() *FriendshipMutation { // Save creates the Friendship in the database. func (fc *FriendshipCreate) Save(ctx context.Context) (*Friendship, error) { fc.defaults() - return withHooks[*Friendship, FriendshipMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) + return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -204,11 +204,15 @@ func (fc *FriendshipCreate) createSpec() (*Friendship, *sqlgraph.CreateSpec) { // FriendshipCreateBulk is the builder for creating many Friendship entities in bulk. type FriendshipCreateBulk struct { config + err error builders []*FriendshipCreate } // Save creates the Friendship entities in the database. func (fcb *FriendshipCreateBulk) Save(ctx context.Context) ([]*Friendship, error) { + if fcb.err != nil { + return nil, fcb.err + } specs := make([]*sqlgraph.CreateSpec, len(fcb.builders)) nodes := make([]*Friendship, len(fcb.builders)) mutators := make([]Mutator, len(fcb.builders)) diff --git a/entgql/internal/todogotype/ent/friendship_delete.go b/entgql/internal/todogotype/ent/friendship_delete.go index 2181f6d4c..4365cadcd 100644 --- a/entgql/internal/todogotype/ent/friendship_delete.go +++ b/entgql/internal/todogotype/ent/friendship_delete.go @@ -41,7 +41,7 @@ func (fd *FriendshipDelete) Where(ps ...predicate.Friendship) *FriendshipDelete // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FriendshipDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) + return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/friendship_update.go b/entgql/internal/todogotype/ent/friendship_update.go index 6c7c5f655..2379623c6 100644 --- a/entgql/internal/todogotype/ent/friendship_update.go +++ b/entgql/internal/todogotype/ent/friendship_update.go @@ -63,12 +63,28 @@ func (fu *FriendshipUpdate) SetUserID(s string) *FriendshipUpdate { return fu } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableUserID(s *string) *FriendshipUpdate { + if s != nil { + fu.SetUserID(*s) + } + return fu +} + // SetFriendID sets the "friend_id" field. func (fu *FriendshipUpdate) SetFriendID(s string) *FriendshipUpdate { fu.mutation.SetFriendID(s) return fu } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableFriendID(s *string) *FriendshipUpdate { + if s != nil { + fu.SetFriendID(*s) + } + return fu +} + // SetUser sets the "user" edge to the User entity. func (fu *FriendshipUpdate) SetUser(u *User) *FriendshipUpdate { return fu.SetUserID(u.ID) @@ -98,7 +114,7 @@ func (fu *FriendshipUpdate) ClearFriend() *FriendshipUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FriendshipUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) + return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -247,12 +263,28 @@ func (fuo *FriendshipUpdateOne) SetUserID(s string) *FriendshipUpdateOne { return fuo } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableUserID(s *string) *FriendshipUpdateOne { + if s != nil { + fuo.SetUserID(*s) + } + return fuo +} + // SetFriendID sets the "friend_id" field. func (fuo *FriendshipUpdateOne) SetFriendID(s string) *FriendshipUpdateOne { fuo.mutation.SetFriendID(s) return fuo } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableFriendID(s *string) *FriendshipUpdateOne { + if s != nil { + fuo.SetFriendID(*s) + } + return fuo +} + // SetUser sets the "user" edge to the User entity. func (fuo *FriendshipUpdateOne) SetUser(u *User) *FriendshipUpdateOne { return fuo.SetUserID(u.ID) @@ -295,7 +327,7 @@ func (fuo *FriendshipUpdateOne) Select(field string, fields ...string) *Friendsh // Save executes the query and returns the updated Friendship entity. func (fuo *FriendshipUpdateOne) Save(ctx context.Context) (*Friendship, error) { - return withHooks[*Friendship, FriendshipMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) + return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/group/where.go b/entgql/internal/todogotype/ent/group/where.go index a8e6a3ca6..c866b741a 100644 --- a/entgql/internal/todogotype/ent/group/where.go +++ b/entgql/internal/todogotype/ent/group/where.go @@ -172,32 +172,15 @@ func HasUsersWith(preds ...predicate.User) predicate.Group { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Group(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/group_create.go b/entgql/internal/todogotype/ent/group_create.go index 146739475..f03e74ec5 100644 --- a/entgql/internal/todogotype/ent/group_create.go +++ b/entgql/internal/todogotype/ent/group_create.go @@ -77,7 +77,7 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { gc.defaults() - return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) + return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -176,11 +176,15 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { // GroupCreateBulk is the builder for creating many Group entities in bulk. type GroupCreateBulk struct { config + err error builders []*GroupCreate } // Save creates the Group entities in the database. func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { + if gcb.err != nil { + return nil, gcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gcb.builders)) nodes := make([]*Group, len(gcb.builders)) mutators := make([]Mutator, len(gcb.builders)) diff --git a/entgql/internal/todogotype/ent/group_delete.go b/entgql/internal/todogotype/ent/group_delete.go index 5879cbf94..c5dba2763 100644 --- a/entgql/internal/todogotype/ent/group_delete.go +++ b/entgql/internal/todogotype/ent/group_delete.go @@ -41,7 +41,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) + return withHooks(ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/group_update.go b/entgql/internal/todogotype/ent/group_update.go index f43880207..2e12848a3 100644 --- a/entgql/internal/todogotype/ent/group_update.go +++ b/entgql/internal/todogotype/ent/group_update.go @@ -99,7 +99,7 @@ func (gu *GroupUpdate) RemoveUsers(u ...*User) *GroupUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) + return withHooks(ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -271,7 +271,7 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { - return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) + return withHooks(ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/mutation.go b/entgql/internal/todogotype/ent/mutation.go index 86e759f7f..cd6fa8b07 100644 --- a/entgql/internal/todogotype/ent/mutation.go +++ b/entgql/internal/todogotype/ent/mutation.go @@ -1773,6 +1773,7 @@ func (m *FriendshipMutation) ResetFriendID() { // ClearUser clears the "user" edge to the User entity. func (m *FriendshipMutation) ClearUser() { m.cleareduser = true + m.clearedFields[friendship.FieldUserID] = struct{}{} } // UserCleared reports if the "user" edge to the User entity was cleared. @@ -1799,6 +1800,7 @@ func (m *FriendshipMutation) ResetUser() { // ClearFriend clears the "friend" edge to the User entity. func (m *FriendshipMutation) ClearFriend() { m.clearedfriend = true + m.clearedFields[friendship.FieldFriendID] = struct{}{} } // FriendCleared reports if the "friend" edge to the User entity was cleared. @@ -3509,6 +3511,7 @@ func (m *TodoMutation) ResetChildren() { // ClearCategory clears the "category" edge to the Category entity. func (m *TodoMutation) ClearCategory() { m.clearedcategory = true + m.clearedFields[todo.FieldCategoryID] = struct{}{} } // CategoryCleared reports if the "category" edge to the Category entity was cleared. diff --git a/entgql/internal/todogotype/ent/pet/where.go b/entgql/internal/todogotype/ent/pet/where.go index ac8cc9209..ce3d3aa7a 100644 --- a/entgql/internal/todogotype/ent/pet/where.go +++ b/entgql/internal/todogotype/ent/pet/where.go @@ -139,32 +139,15 @@ func NameContainsFold(v string) predicate.Pet { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Pet(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/pet_create.go b/entgql/internal/todogotype/ent/pet_create.go index 2909e2319..4aa254342 100644 --- a/entgql/internal/todogotype/ent/pet_create.go +++ b/entgql/internal/todogotype/ent/pet_create.go @@ -62,7 +62,7 @@ func (pc *PetCreate) Mutation() *PetMutation { // Save creates the Pet in the database. func (pc *PetCreate) Save(ctx context.Context) (*Pet, error) { pc.defaults() - return withHooks[*Pet, PetMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -142,11 +142,15 @@ func (pc *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) { // PetCreateBulk is the builder for creating many Pet entities in bulk. type PetCreateBulk struct { config + err error builders []*PetCreate } // Save creates the Pet entities in the database. func (pcb *PetCreateBulk) Save(ctx context.Context) ([]*Pet, error) { + if pcb.err != nil { + return nil, pcb.err + } specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) nodes := make([]*Pet, len(pcb.builders)) mutators := make([]Mutator, len(pcb.builders)) diff --git a/entgql/internal/todogotype/ent/pet_delete.go b/entgql/internal/todogotype/ent/pet_delete.go index 96d533fec..d5a4824e8 100644 --- a/entgql/internal/todogotype/ent/pet_delete.go +++ b/entgql/internal/todogotype/ent/pet_delete.go @@ -41,7 +41,7 @@ func (pd *PetDelete) Where(ps ...predicate.Pet) *PetDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *PetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/pet_update.go b/entgql/internal/todogotype/ent/pet_update.go index 3c9904f2a..f1e5072ef 100644 --- a/entgql/internal/todogotype/ent/pet_update.go +++ b/entgql/internal/todogotype/ent/pet_update.go @@ -62,7 +62,7 @@ func (pu *PetUpdate) Mutation() *PetMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -153,7 +153,7 @@ func (puo *PetUpdateOne) Select(field string, fields ...string) *PetUpdateOne { // Save executes the query and returns the updated Pet entity. func (puo *PetUpdateOne) Save(ctx context.Context) (*Pet, error) { - return withHooks[*Pet, PetMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/runtime/runtime.go b/entgql/internal/todogotype/ent/runtime/runtime.go index 313e872ff..83caeb839 100644 --- a/entgql/internal/todogotype/ent/runtime/runtime.go +++ b/entgql/internal/todogotype/ent/runtime/runtime.go @@ -19,6 +19,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entgql/internal/todogotype/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entgql/internal/todogotype/ent/todo/where.go b/entgql/internal/todogotype/ent/todo/where.go index e216acfc0..d5d0f7b9a 100644 --- a/entgql/internal/todogotype/ent/todo/where.go +++ b/entgql/internal/todogotype/ent/todo/where.go @@ -524,32 +524,15 @@ func HasSecretWith(preds ...predicate.VerySecret) predicate.Todo { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Todo(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/todo_create.go b/entgql/internal/todogotype/ent/todo_create.go index c3ac9e211..3c4da28f1 100644 --- a/entgql/internal/todogotype/ent/todo_create.go +++ b/entgql/internal/todogotype/ent/todo_create.go @@ -196,7 +196,7 @@ func (tc *TodoCreate) Mutation() *TodoMutation { // Save creates the Todo in the database. func (tc *TodoCreate) Save(ctx context.Context) (*Todo, error) { tc.defaults() - return withHooks[*Todo, TodoMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -401,11 +401,15 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { // TodoCreateBulk is the builder for creating many Todo entities in bulk. type TodoCreateBulk struct { config + err error builders []*TodoCreate } // Save creates the Todo entities in the database. func (tcb *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Todo, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) diff --git a/entgql/internal/todogotype/ent/todo_delete.go b/entgql/internal/todogotype/ent/todo_delete.go index 78613cf3a..697597f21 100644 --- a/entgql/internal/todogotype/ent/todo_delete.go +++ b/entgql/internal/todogotype/ent/todo_delete.go @@ -41,7 +41,7 @@ func (td *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TodoDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/todo_update.go b/entgql/internal/todogotype/ent/todo_update.go index 2c9ef3a57..ac6f78363 100644 --- a/entgql/internal/todogotype/ent/todo_update.go +++ b/entgql/internal/todogotype/ent/todo_update.go @@ -50,6 +50,14 @@ func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate { return tu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableStatus(t *todo.Status) *TodoUpdate { + if t != nil { + tu.SetStatus(*t) + } + return tu +} + // SetPriority sets the "priority" field. func (tu *TodoUpdate) SetPriority(i int) *TodoUpdate { tu.mutation.ResetPriority() @@ -77,6 +85,14 @@ func (tu *TodoUpdate) SetText(s string) *TodoUpdate { return tu } +// SetNillableText sets the "text" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { + if s != nil { + tu.SetText(*s) + } + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -230,7 +246,7 @@ func (tu *TodoUpdate) ClearSecret() *TodoUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TodoUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -457,6 +473,14 @@ func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne { return tuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableStatus(t *todo.Status) *TodoUpdateOne { + if t != nil { + tuo.SetStatus(*t) + } + return tuo +} + // SetPriority sets the "priority" field. func (tuo *TodoUpdateOne) SetPriority(i int) *TodoUpdateOne { tuo.mutation.ResetPriority() @@ -484,6 +508,14 @@ func (tuo *TodoUpdateOne) SetText(s string) *TodoUpdateOne { return tuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetText(*s) + } + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -650,7 +682,7 @@ func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne // Save executes the query and returns the updated Todo entity. func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { - return withHooks[*Todo, TodoMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/user/where.go b/entgql/internal/todogotype/ent/user/where.go index 90193af7a..91e2b8693 100644 --- a/entgql/internal/todogotype/ent/user/where.go +++ b/entgql/internal/todogotype/ent/user/where.go @@ -218,32 +218,15 @@ func HasFriendshipsWith(preds ...predicate.Friendship) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/user_create.go b/entgql/internal/todogotype/ent/user_create.go index 83b8d991c..889f778de 100644 --- a/entgql/internal/todogotype/ent/user_create.go +++ b/entgql/internal/todogotype/ent/user_create.go @@ -108,7 +108,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { uc.defaults() - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -243,11 +243,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entgql/internal/todogotype/ent/user_delete.go b/entgql/internal/todogotype/ent/user_delete.go index 125171025..64ff12be3 100644 --- a/entgql/internal/todogotype/ent/user_delete.go +++ b/entgql/internal/todogotype/ent/user_delete.go @@ -41,7 +41,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/user_update.go b/entgql/internal/todogotype/ent/user_update.go index 13d9d1635..5de4de81f 100644 --- a/entgql/internal/todogotype/ent/user_update.go +++ b/entgql/internal/todogotype/ent/user_update.go @@ -172,7 +172,7 @@ func (uu *UserUpdate) RemoveFriendships(f ...*Friendship) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -518,7 +518,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/verysecret/where.go b/entgql/internal/todogotype/ent/verysecret/where.go index 898a53ec9..9002de00f 100644 --- a/entgql/internal/todogotype/ent/verysecret/where.go +++ b/entgql/internal/todogotype/ent/verysecret/where.go @@ -148,32 +148,15 @@ func PasswordContainsFold(v string) predicate.VerySecret { // And groups predicates with the AND operator between them. func And(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.VerySecret(sql.NotPredicates(p)) } diff --git a/entgql/internal/todogotype/ent/verysecret_create.go b/entgql/internal/todogotype/ent/verysecret_create.go index d95d41867..9b04e27ff 100644 --- a/entgql/internal/todogotype/ent/verysecret_create.go +++ b/entgql/internal/todogotype/ent/verysecret_create.go @@ -61,7 +61,7 @@ func (vsc *VerySecretCreate) Mutation() *VerySecretMutation { // Save creates the VerySecret in the database. func (vsc *VerySecretCreate) Save(ctx context.Context) (*VerySecret, error) { vsc.defaults() - return withHooks[*VerySecret, VerySecretMutation](ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) + return withHooks(ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -144,11 +144,15 @@ func (vsc *VerySecretCreate) createSpec() (*VerySecret, *sqlgraph.CreateSpec) { // VerySecretCreateBulk is the builder for creating many VerySecret entities in bulk. type VerySecretCreateBulk struct { config + err error builders []*VerySecretCreate } // Save creates the VerySecret entities in the database. func (vscb *VerySecretCreateBulk) Save(ctx context.Context) ([]*VerySecret, error) { + if vscb.err != nil { + return nil, vscb.err + } specs := make([]*sqlgraph.CreateSpec, len(vscb.builders)) nodes := make([]*VerySecret, len(vscb.builders)) mutators := make([]Mutator, len(vscb.builders)) diff --git a/entgql/internal/todogotype/ent/verysecret_delete.go b/entgql/internal/todogotype/ent/verysecret_delete.go index d5c34c6c8..16a7c5082 100644 --- a/entgql/internal/todogotype/ent/verysecret_delete.go +++ b/entgql/internal/todogotype/ent/verysecret_delete.go @@ -41,7 +41,7 @@ func (vsd *VerySecretDelete) Where(ps ...predicate.VerySecret) *VerySecretDelete // Exec executes the deletion query and returns how many vertices were deleted. func (vsd *VerySecretDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) + return withHooks(ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todogotype/ent/verysecret_update.go b/entgql/internal/todogotype/ent/verysecret_update.go index e73c713a8..1fbcc41e5 100644 --- a/entgql/internal/todogotype/ent/verysecret_update.go +++ b/entgql/internal/todogotype/ent/verysecret_update.go @@ -47,6 +47,14 @@ func (vsu *VerySecretUpdate) SetPassword(s string) *VerySecretUpdate { return vsu } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsu *VerySecretUpdate) SetNillablePassword(s *string) *VerySecretUpdate { + if s != nil { + vsu.SetPassword(*s) + } + return vsu +} + // Mutation returns the VerySecretMutation object of the builder. func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { return vsu.mutation @@ -54,7 +62,7 @@ func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (vsu *VerySecretUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) + return withHooks(ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -117,6 +125,14 @@ func (vsuo *VerySecretUpdateOne) SetPassword(s string) *VerySecretUpdateOne { return vsuo } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsuo *VerySecretUpdateOne) SetNillablePassword(s *string) *VerySecretUpdateOne { + if s != nil { + vsuo.SetPassword(*s) + } + return vsuo +} + // Mutation returns the VerySecretMutation object of the builder. func (vsuo *VerySecretUpdateOne) Mutation() *VerySecretMutation { return vsuo.mutation @@ -137,7 +153,7 @@ func (vsuo *VerySecretUpdateOne) Select(field string, fields ...string) *VerySec // Save executes the query and returns the updated VerySecret entity. func (vsuo *VerySecretUpdateOne) Save(ctx context.Context) (*VerySecret, error) { - return withHooks[*VerySecret, VerySecretMutation](ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) + return withHooks(ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/billproduct/where.go b/entgql/internal/todopulid/ent/billproduct/where.go index ffc1ce09e..0063f5328 100644 --- a/entgql/internal/todopulid/ent/billproduct/where.go +++ b/entgql/internal/todopulid/ent/billproduct/where.go @@ -254,32 +254,15 @@ func QuantityLTE(v uint64) predicate.BillProduct { // And groups predicates with the AND operator between them. func And(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.BillProduct(sql.NotPredicates(p)) } diff --git a/entgql/internal/todopulid/ent/billproduct_create.go b/entgql/internal/todopulid/ent/billproduct_create.go index e5c2a13d8..81ec7dfed 100644 --- a/entgql/internal/todopulid/ent/billproduct_create.go +++ b/entgql/internal/todopulid/ent/billproduct_create.go @@ -74,7 +74,7 @@ func (bpc *BillProductCreate) Mutation() *BillProductMutation { // Save creates the BillProduct in the database. func (bpc *BillProductCreate) Save(ctx context.Context) (*BillProduct, error) { bpc.defaults() - return withHooks[*BillProduct, BillProductMutation](ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) + return withHooks(ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -171,11 +171,15 @@ func (bpc *BillProductCreate) createSpec() (*BillProduct, *sqlgraph.CreateSpec) // BillProductCreateBulk is the builder for creating many BillProduct entities in bulk. type BillProductCreateBulk struct { config + err error builders []*BillProductCreate } // Save creates the BillProduct entities in the database. func (bpcb *BillProductCreateBulk) Save(ctx context.Context) ([]*BillProduct, error) { + if bpcb.err != nil { + return nil, bpcb.err + } specs := make([]*sqlgraph.CreateSpec, len(bpcb.builders)) nodes := make([]*BillProduct, len(bpcb.builders)) mutators := make([]Mutator, len(bpcb.builders)) diff --git a/entgql/internal/todopulid/ent/billproduct_delete.go b/entgql/internal/todopulid/ent/billproduct_delete.go index 1d10a37d5..1ac3fbb1a 100644 --- a/entgql/internal/todopulid/ent/billproduct_delete.go +++ b/entgql/internal/todopulid/ent/billproduct_delete.go @@ -41,7 +41,7 @@ func (bpd *BillProductDelete) Where(ps ...predicate.BillProduct) *BillProductDel // Exec executes the deletion query and returns how many vertices were deleted. func (bpd *BillProductDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) + return withHooks(ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/billproduct_update.go b/entgql/internal/todopulid/ent/billproduct_update.go index f5d0b9bbd..81207fee3 100644 --- a/entgql/internal/todopulid/ent/billproduct_update.go +++ b/entgql/internal/todopulid/ent/billproduct_update.go @@ -47,12 +47,28 @@ func (bpu *BillProductUpdate) SetName(s string) *BillProductUpdate { return bpu } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableName(s *string) *BillProductUpdate { + if s != nil { + bpu.SetName(*s) + } + return bpu +} + // SetSku sets the "sku" field. func (bpu *BillProductUpdate) SetSku(s string) *BillProductUpdate { bpu.mutation.SetSku(s) return bpu } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableSku(s *string) *BillProductUpdate { + if s != nil { + bpu.SetSku(*s) + } + return bpu +} + // SetQuantity sets the "quantity" field. func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { bpu.mutation.ResetQuantity() @@ -60,6 +76,14 @@ func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { return bpu } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableQuantity(u *uint64) *BillProductUpdate { + if u != nil { + bpu.SetQuantity(*u) + } + return bpu +} + // AddQuantity adds u to the "quantity" field. func (bpu *BillProductUpdate) AddQuantity(u int64) *BillProductUpdate { bpu.mutation.AddQuantity(u) @@ -73,7 +97,7 @@ func (bpu *BillProductUpdate) Mutation() *BillProductMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (bpu *BillProductUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) + return withHooks(ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -145,12 +169,28 @@ func (bpuo *BillProductUpdateOne) SetName(s string) *BillProductUpdateOne { return bpuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableName(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetName(*s) + } + return bpuo +} + // SetSku sets the "sku" field. func (bpuo *BillProductUpdateOne) SetSku(s string) *BillProductUpdateOne { bpuo.mutation.SetSku(s) return bpuo } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableSku(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetSku(*s) + } + return bpuo +} + // SetQuantity sets the "quantity" field. func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { bpuo.mutation.ResetQuantity() @@ -158,6 +198,14 @@ func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { return bpuo } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableQuantity(u *uint64) *BillProductUpdateOne { + if u != nil { + bpuo.SetQuantity(*u) + } + return bpuo +} + // AddQuantity adds u to the "quantity" field. func (bpuo *BillProductUpdateOne) AddQuantity(u int64) *BillProductUpdateOne { bpuo.mutation.AddQuantity(u) @@ -184,7 +232,7 @@ func (bpuo *BillProductUpdateOne) Select(field string, fields ...string) *BillPr // Save executes the query and returns the updated BillProduct entity. func (bpuo *BillProductUpdateOne) Save(ctx context.Context) (*BillProduct, error) { - return withHooks[*BillProduct, BillProductMutation](ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) + return withHooks(ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/category/where.go b/entgql/internal/todopulid/ent/category/where.go index 76feef5d3..67fd18815 100644 --- a/entgql/internal/todopulid/ent/category/where.go +++ b/entgql/internal/todopulid/ent/category/where.go @@ -409,32 +409,15 @@ func HasSubCategoriesWith(preds ...predicate.Category) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entgql/internal/todopulid/ent/category_create.go b/entgql/internal/todopulid/ent/category_create.go index 5df084799..520504003 100644 --- a/entgql/internal/todopulid/ent/category_create.go +++ b/entgql/internal/todopulid/ent/category_create.go @@ -147,7 +147,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { cc.defaults() - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -299,11 +299,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entgql/internal/todopulid/ent/category_delete.go b/entgql/internal/todopulid/ent/category_delete.go index 53f8a1ece..54d1a26a9 100644 --- a/entgql/internal/todopulid/ent/category_delete.go +++ b/entgql/internal/todopulid/ent/category_delete.go @@ -41,7 +41,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/category_update.go b/entgql/internal/todopulid/ent/category_update.go index 4832c0abd..ee945dc28 100644 --- a/entgql/internal/todopulid/ent/category_update.go +++ b/entgql/internal/todopulid/ent/category_update.go @@ -52,12 +52,28 @@ func (cu *CategoryUpdate) SetText(s string) *CategoryUpdate { return cu } +// SetNillableText sets the "text" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableText(s *string) *CategoryUpdate { + if s != nil { + cu.SetText(*s) + } + return cu +} + // SetStatus sets the "status" field. func (cu *CategoryUpdate) SetStatus(c category.Status) *CategoryUpdate { cu.mutation.SetStatus(c) return cu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableStatus(c *category.Status) *CategoryUpdate { + if c != nil { + cu.SetStatus(*c) + } + return cu +} + // SetConfig sets the "config" field. func (cu *CategoryUpdate) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdate { cu.mutation.SetConfig(sc) @@ -233,7 +249,7 @@ func (cu *CategoryUpdate) RemoveSubCategories(c ...*Category) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -448,12 +464,28 @@ func (cuo *CategoryUpdateOne) SetText(s string) *CategoryUpdateOne { return cuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableText(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetText(*s) + } + return cuo +} + // SetStatus sets the "status" field. func (cuo *CategoryUpdateOne) SetStatus(c category.Status) *CategoryUpdateOne { cuo.mutation.SetStatus(c) return cuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableStatus(c *category.Status) *CategoryUpdateOne { + if c != nil { + cuo.SetStatus(*c) + } + return cuo +} + // SetConfig sets the "config" field. func (cuo *CategoryUpdateOne) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdateOne { cuo.mutation.SetConfig(sc) @@ -642,7 +674,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/client.go b/entgql/internal/todopulid/ent/client.go index a83c50d26..dd267966f 100644 --- a/entgql/internal/todopulid/ent/client.go +++ b/entgql/internal/todopulid/ent/client.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entgql/internal/todopulid/ent/migrate" "entgo.io/contrib/entgql/internal/todopulid/ent/schema/pulid" @@ -144,11 +145,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -292,6 +296,21 @@ func (c *BillProductClient) CreateBulk(builders ...*BillProductCreate) *BillProd return &BillProductCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *BillProductClient) MapCreateBulk(slice any, setFunc func(*BillProductCreate, int)) *BillProductCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &BillProductCreateBulk{err: fmt.Errorf("calling to BillProductClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*BillProductCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &BillProductCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for BillProduct. func (c *BillProductClient) Update() *BillProductUpdate { mutation := newBillProductMutation(c.config, OpUpdate) @@ -410,6 +429,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -560,6 +594,21 @@ func (c *FriendshipClient) CreateBulk(builders ...*FriendshipCreate) *Friendship return &FriendshipCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *FriendshipClient) MapCreateBulk(slice any, setFunc func(*FriendshipCreate, int)) *FriendshipCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &FriendshipCreateBulk{err: fmt.Errorf("calling to FriendshipClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*FriendshipCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &FriendshipCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Friendship. func (c *FriendshipClient) Update() *FriendshipUpdate { mutation := newFriendshipMutation(c.config, OpUpdate) @@ -710,6 +759,21 @@ func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { return &GroupCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Group. func (c *GroupClient) Update() *GroupUpdate { mutation := newGroupMutation(c.config, OpUpdate) @@ -844,6 +908,21 @@ func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk { return &TodoCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TodoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TodoCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Todo. func (c *TodoClient) Update() *TodoUpdate { mutation := newTodoMutation(c.config, OpUpdate) @@ -1026,6 +1105,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) @@ -1192,6 +1286,21 @@ func (c *VerySecretClient) CreateBulk(builders ...*VerySecretCreate) *VerySecret return &VerySecretCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *VerySecretClient) MapCreateBulk(slice any, setFunc func(*VerySecretCreate, int)) *VerySecretCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &VerySecretCreateBulk{err: fmt.Errorf("calling to VerySecretClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*VerySecretCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &VerySecretCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for VerySecret. func (c *VerySecretClient) Update() *VerySecretUpdate { mutation := newVerySecretMutation(c.config, OpUpdate) diff --git a/entgql/internal/todopulid/ent/friendship/where.go b/entgql/internal/todopulid/ent/friendship/where.go index f79af66c2..49666e6ee 100644 --- a/entgql/internal/todopulid/ent/friendship/where.go +++ b/entgql/internal/todopulid/ent/friendship/where.go @@ -313,32 +313,15 @@ func HasFriendWith(preds ...predicate.User) predicate.Friendship { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Friendship(sql.NotPredicates(p)) } diff --git a/entgql/internal/todopulid/ent/friendship_create.go b/entgql/internal/todopulid/ent/friendship_create.go index b3a86c75a..8117b0b8e 100644 --- a/entgql/internal/todopulid/ent/friendship_create.go +++ b/entgql/internal/todopulid/ent/friendship_create.go @@ -94,7 +94,7 @@ func (fc *FriendshipCreate) Mutation() *FriendshipMutation { // Save creates the Friendship in the database. func (fc *FriendshipCreate) Save(ctx context.Context) (*Friendship, error) { fc.defaults() - return withHooks[*Friendship, FriendshipMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) + return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -227,11 +227,15 @@ func (fc *FriendshipCreate) createSpec() (*Friendship, *sqlgraph.CreateSpec) { // FriendshipCreateBulk is the builder for creating many Friendship entities in bulk. type FriendshipCreateBulk struct { config + err error builders []*FriendshipCreate } // Save creates the Friendship entities in the database. func (fcb *FriendshipCreateBulk) Save(ctx context.Context) ([]*Friendship, error) { + if fcb.err != nil { + return nil, fcb.err + } specs := make([]*sqlgraph.CreateSpec, len(fcb.builders)) nodes := make([]*Friendship, len(fcb.builders)) mutators := make([]Mutator, len(fcb.builders)) diff --git a/entgql/internal/todopulid/ent/friendship_delete.go b/entgql/internal/todopulid/ent/friendship_delete.go index e20661159..ee544beaf 100644 --- a/entgql/internal/todopulid/ent/friendship_delete.go +++ b/entgql/internal/todopulid/ent/friendship_delete.go @@ -41,7 +41,7 @@ func (fd *FriendshipDelete) Where(ps ...predicate.Friendship) *FriendshipDelete // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FriendshipDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) + return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/friendship_update.go b/entgql/internal/todopulid/ent/friendship_update.go index 4e5196821..7e37f74cd 100644 --- a/entgql/internal/todopulid/ent/friendship_update.go +++ b/entgql/internal/todopulid/ent/friendship_update.go @@ -64,12 +64,28 @@ func (fu *FriendshipUpdate) SetUserID(pu pulid.ID) *FriendshipUpdate { return fu } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableUserID(pu *pulid.ID) *FriendshipUpdate { + if pu != nil { + fu.SetUserID(*pu) + } + return fu +} + // SetFriendID sets the "friend_id" field. func (fu *FriendshipUpdate) SetFriendID(pu pulid.ID) *FriendshipUpdate { fu.mutation.SetFriendID(pu) return fu } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableFriendID(pu *pulid.ID) *FriendshipUpdate { + if pu != nil { + fu.SetFriendID(*pu) + } + return fu +} + // SetUser sets the "user" edge to the User entity. func (fu *FriendshipUpdate) SetUser(u *User) *FriendshipUpdate { return fu.SetUserID(u.ID) @@ -99,7 +115,7 @@ func (fu *FriendshipUpdate) ClearFriend() *FriendshipUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FriendshipUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) + return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -248,12 +264,28 @@ func (fuo *FriendshipUpdateOne) SetUserID(pu pulid.ID) *FriendshipUpdateOne { return fuo } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableUserID(pu *pulid.ID) *FriendshipUpdateOne { + if pu != nil { + fuo.SetUserID(*pu) + } + return fuo +} + // SetFriendID sets the "friend_id" field. func (fuo *FriendshipUpdateOne) SetFriendID(pu pulid.ID) *FriendshipUpdateOne { fuo.mutation.SetFriendID(pu) return fuo } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableFriendID(pu *pulid.ID) *FriendshipUpdateOne { + if pu != nil { + fuo.SetFriendID(*pu) + } + return fuo +} + // SetUser sets the "user" edge to the User entity. func (fuo *FriendshipUpdateOne) SetUser(u *User) *FriendshipUpdateOne { return fuo.SetUserID(u.ID) @@ -296,7 +328,7 @@ func (fuo *FriendshipUpdateOne) Select(field string, fields ...string) *Friendsh // Save executes the query and returns the updated Friendship entity. func (fuo *FriendshipUpdateOne) Save(ctx context.Context) (*Friendship, error) { - return withHooks[*Friendship, FriendshipMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) + return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/group/where.go b/entgql/internal/todopulid/ent/group/where.go index bf8e03bfb..3bac7053e 100644 --- a/entgql/internal/todopulid/ent/group/where.go +++ b/entgql/internal/todopulid/ent/group/where.go @@ -163,32 +163,15 @@ func HasUsersWith(preds ...predicate.User) predicate.Group { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Group(sql.NotPredicates(p)) } diff --git a/entgql/internal/todopulid/ent/group_create.go b/entgql/internal/todopulid/ent/group_create.go index d2d161739..12dbed4a4 100644 --- a/entgql/internal/todopulid/ent/group_create.go +++ b/entgql/internal/todopulid/ent/group_create.go @@ -86,7 +86,7 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { gc.defaults() - return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) + return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -189,11 +189,15 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { // GroupCreateBulk is the builder for creating many Group entities in bulk. type GroupCreateBulk struct { config + err error builders []*GroupCreate } // Save creates the Group entities in the database. func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { + if gcb.err != nil { + return nil, gcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gcb.builders)) nodes := make([]*Group, len(gcb.builders)) mutators := make([]Mutator, len(gcb.builders)) diff --git a/entgql/internal/todopulid/ent/group_delete.go b/entgql/internal/todopulid/ent/group_delete.go index e551c5498..5ed976e25 100644 --- a/entgql/internal/todopulid/ent/group_delete.go +++ b/entgql/internal/todopulid/ent/group_delete.go @@ -41,7 +41,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) + return withHooks(ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/group_update.go b/entgql/internal/todopulid/ent/group_update.go index 9ccc7215a..521856ca0 100644 --- a/entgql/internal/todopulid/ent/group_update.go +++ b/entgql/internal/todopulid/ent/group_update.go @@ -100,7 +100,7 @@ func (gu *GroupUpdate) RemoveUsers(u ...*User) *GroupUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) + return withHooks(ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -272,7 +272,7 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { - return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) + return withHooks(ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/mutation.go b/entgql/internal/todopulid/ent/mutation.go index 4b39c2cb3..5989c6ff2 100644 --- a/entgql/internal/todopulid/ent/mutation.go +++ b/entgql/internal/todopulid/ent/mutation.go @@ -1783,6 +1783,7 @@ func (m *FriendshipMutation) ResetFriendID() { // ClearUser clears the "user" edge to the User entity. func (m *FriendshipMutation) ClearUser() { m.cleareduser = true + m.clearedFields[friendship.FieldUserID] = struct{}{} } // UserCleared reports if the "user" edge to the User entity was cleared. @@ -1809,6 +1810,7 @@ func (m *FriendshipMutation) ResetUser() { // ClearFriend clears the "friend" edge to the User entity. func (m *FriendshipMutation) ClearFriend() { m.clearedfriend = true + m.clearedFields[friendship.FieldFriendID] = struct{}{} } // FriendCleared reports if the "friend" edge to the User entity was cleared. @@ -3187,6 +3189,7 @@ func (m *TodoMutation) ResetChildren() { // ClearCategory clears the "category" edge to the Category entity. func (m *TodoMutation) ClearCategory() { m.clearedcategory = true + m.clearedFields[todo.FieldCategoryID] = struct{}{} } // CategoryCleared reports if the "category" edge to the Category entity was cleared. diff --git a/entgql/internal/todopulid/ent/runtime/runtime.go b/entgql/internal/todopulid/ent/runtime/runtime.go index 27d6af690..c79b8d1c4 100644 --- a/entgql/internal/todopulid/ent/runtime/runtime.go +++ b/entgql/internal/todopulid/ent/runtime/runtime.go @@ -19,6 +19,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entgql/internal/todopulid/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entgql/internal/todopulid/ent/todo/where.go b/entgql/internal/todopulid/ent/todo/where.go index 6983db1a8..305ac1136 100644 --- a/entgql/internal/todopulid/ent/todo/where.go +++ b/entgql/internal/todopulid/ent/todo/where.go @@ -514,32 +514,15 @@ func HasSecretWith(preds ...predicate.VerySecret) predicate.Todo { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Todo(sql.NotPredicates(p)) } diff --git a/entgql/internal/todopulid/ent/todo_create.go b/entgql/internal/todopulid/ent/todo_create.go index 9d250fb76..cfcee90ca 100644 --- a/entgql/internal/todopulid/ent/todo_create.go +++ b/entgql/internal/todopulid/ent/todo_create.go @@ -196,7 +196,7 @@ func (tc *TodoCreate) Mutation() *TodoMutation { // Save creates the Todo in the database. func (tc *TodoCreate) Save(ctx context.Context) (*Todo, error) { tc.defaults() - return withHooks[*Todo, TodoMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -401,11 +401,15 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { // TodoCreateBulk is the builder for creating many Todo entities in bulk. type TodoCreateBulk struct { config + err error builders []*TodoCreate } // Save creates the Todo entities in the database. func (tcb *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Todo, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) diff --git a/entgql/internal/todopulid/ent/todo_delete.go b/entgql/internal/todopulid/ent/todo_delete.go index c0a83d6b0..530240061 100644 --- a/entgql/internal/todopulid/ent/todo_delete.go +++ b/entgql/internal/todopulid/ent/todo_delete.go @@ -41,7 +41,7 @@ func (td *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TodoDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/todo_update.go b/entgql/internal/todopulid/ent/todo_update.go index 1d59bbf43..c9932eefa 100644 --- a/entgql/internal/todopulid/ent/todo_update.go +++ b/entgql/internal/todopulid/ent/todo_update.go @@ -51,6 +51,14 @@ func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate { return tu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableStatus(t *todo.Status) *TodoUpdate { + if t != nil { + tu.SetStatus(*t) + } + return tu +} + // SetPriority sets the "priority" field. func (tu *TodoUpdate) SetPriority(i int) *TodoUpdate { tu.mutation.ResetPriority() @@ -78,6 +86,14 @@ func (tu *TodoUpdate) SetText(s string) *TodoUpdate { return tu } +// SetNillableText sets the "text" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { + if s != nil { + tu.SetText(*s) + } + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -231,7 +247,7 @@ func (tu *TodoUpdate) ClearSecret() *TodoUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TodoUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -458,6 +474,14 @@ func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne { return tuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableStatus(t *todo.Status) *TodoUpdateOne { + if t != nil { + tuo.SetStatus(*t) + } + return tuo +} + // SetPriority sets the "priority" field. func (tuo *TodoUpdateOne) SetPriority(i int) *TodoUpdateOne { tuo.mutation.ResetPriority() @@ -485,6 +509,14 @@ func (tuo *TodoUpdateOne) SetText(s string) *TodoUpdateOne { return tuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetText(*s) + } + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -651,7 +683,7 @@ func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne // Save executes the query and returns the updated Todo entity. func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { - return withHooks[*Todo, TodoMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/user/where.go b/entgql/internal/todopulid/ent/user/where.go index ecc0d0b42..0d29124f2 100644 --- a/entgql/internal/todopulid/ent/user/where.go +++ b/entgql/internal/todopulid/ent/user/where.go @@ -345,32 +345,15 @@ func HasFriendshipsWith(preds ...predicate.Friendship) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entgql/internal/todopulid/ent/user_create.go b/entgql/internal/todopulid/ent/user_create.go index 32dd0362b..eed7a4cc3 100644 --- a/entgql/internal/todopulid/ent/user_create.go +++ b/entgql/internal/todopulid/ent/user_create.go @@ -158,7 +158,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { uc.defaults() - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -326,11 +326,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entgql/internal/todopulid/ent/user_delete.go b/entgql/internal/todopulid/ent/user_delete.go index b597b22b2..5ef2acad7 100644 --- a/entgql/internal/todopulid/ent/user_delete.go +++ b/entgql/internal/todopulid/ent/user_delete.go @@ -41,7 +41,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/user_update.go b/entgql/internal/todopulid/ent/user_update.go index dac0302be..b0af0a967 100644 --- a/entgql/internal/todopulid/ent/user_update.go +++ b/entgql/internal/todopulid/ent/user_update.go @@ -226,7 +226,7 @@ func (uu *UserUpdate) RemoveFriendships(f ...*Friendship) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -651,7 +651,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/verysecret/where.go b/entgql/internal/todopulid/ent/verysecret/where.go index 867bcab90..ff85605e8 100644 --- a/entgql/internal/todopulid/ent/verysecret/where.go +++ b/entgql/internal/todopulid/ent/verysecret/where.go @@ -139,32 +139,15 @@ func PasswordContainsFold(v string) predicate.VerySecret { // And groups predicates with the AND operator between them. func And(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.VerySecret(sql.NotPredicates(p)) } diff --git a/entgql/internal/todopulid/ent/verysecret_create.go b/entgql/internal/todopulid/ent/verysecret_create.go index 186098579..75f31c958 100644 --- a/entgql/internal/todopulid/ent/verysecret_create.go +++ b/entgql/internal/todopulid/ent/verysecret_create.go @@ -62,7 +62,7 @@ func (vsc *VerySecretCreate) Mutation() *VerySecretMutation { // Save creates the VerySecret in the database. func (vsc *VerySecretCreate) Save(ctx context.Context) (*VerySecret, error) { vsc.defaults() - return withHooks[*VerySecret, VerySecretMutation](ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) + return withHooks(ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -145,11 +145,15 @@ func (vsc *VerySecretCreate) createSpec() (*VerySecret, *sqlgraph.CreateSpec) { // VerySecretCreateBulk is the builder for creating many VerySecret entities in bulk. type VerySecretCreateBulk struct { config + err error builders []*VerySecretCreate } // Save creates the VerySecret entities in the database. func (vscb *VerySecretCreateBulk) Save(ctx context.Context) ([]*VerySecret, error) { + if vscb.err != nil { + return nil, vscb.err + } specs := make([]*sqlgraph.CreateSpec, len(vscb.builders)) nodes := make([]*VerySecret, len(vscb.builders)) mutators := make([]Mutator, len(vscb.builders)) diff --git a/entgql/internal/todopulid/ent/verysecret_delete.go b/entgql/internal/todopulid/ent/verysecret_delete.go index bf7b6d0fe..26cd459ba 100644 --- a/entgql/internal/todopulid/ent/verysecret_delete.go +++ b/entgql/internal/todopulid/ent/verysecret_delete.go @@ -41,7 +41,7 @@ func (vsd *VerySecretDelete) Where(ps ...predicate.VerySecret) *VerySecretDelete // Exec executes the deletion query and returns how many vertices were deleted. func (vsd *VerySecretDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) + return withHooks(ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todopulid/ent/verysecret_update.go b/entgql/internal/todopulid/ent/verysecret_update.go index e462c3057..d3592e533 100644 --- a/entgql/internal/todopulid/ent/verysecret_update.go +++ b/entgql/internal/todopulid/ent/verysecret_update.go @@ -47,6 +47,14 @@ func (vsu *VerySecretUpdate) SetPassword(s string) *VerySecretUpdate { return vsu } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsu *VerySecretUpdate) SetNillablePassword(s *string) *VerySecretUpdate { + if s != nil { + vsu.SetPassword(*s) + } + return vsu +} + // Mutation returns the VerySecretMutation object of the builder. func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { return vsu.mutation @@ -54,7 +62,7 @@ func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (vsu *VerySecretUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) + return withHooks(ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -117,6 +125,14 @@ func (vsuo *VerySecretUpdateOne) SetPassword(s string) *VerySecretUpdateOne { return vsuo } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsuo *VerySecretUpdateOne) SetNillablePassword(s *string) *VerySecretUpdateOne { + if s != nil { + vsuo.SetPassword(*s) + } + return vsuo +} + // Mutation returns the VerySecretMutation object of the builder. func (vsuo *VerySecretUpdateOne) Mutation() *VerySecretMutation { return vsuo.mutation @@ -137,7 +153,7 @@ func (vsuo *VerySecretUpdateOne) Select(field string, fields ...string) *VerySec // Save executes the query and returns the updated VerySecret entity. func (vsuo *VerySecretUpdateOne) Save(ctx context.Context) (*VerySecret, error) { - return withHooks[*VerySecret, VerySecretMutation](ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) + return withHooks(ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todopulid/server/server.go b/entgql/internal/todopulid/server/server.go index 92e758f1b..ad8895878 100644 --- a/entgql/internal/todopulid/server/server.go +++ b/entgql/internal/todopulid/server/server.go @@ -16,6 +16,7 @@ package main import ( "context" "net/http" + "time" "entgo.io/contrib/entgql" todopulid "entgo.io/contrib/entgql/internal/todopulid" @@ -78,7 +79,11 @@ func main() { http.Handle("/query", srv) log.Info("listening on", zap.String("address", cli.Addr)) - if err := http.ListenAndServe(cli.Addr, nil); err != nil { + server := &http.Server{ + Addr: cli.Addr, + ReadHeaderTimeout: 30 * time.Second, + } + if err := server.ListenAndServe(); err != nil { log.Error("http server terminated", zap.Error(err)) } } diff --git a/entgql/internal/todouuid/ent/billproduct/where.go b/entgql/internal/todouuid/ent/billproduct/where.go index bcd6dab8a..7bfdeadbb 100644 --- a/entgql/internal/todouuid/ent/billproduct/where.go +++ b/entgql/internal/todouuid/ent/billproduct/where.go @@ -254,32 +254,15 @@ func QuantityLTE(v uint64) predicate.BillProduct { // And groups predicates with the AND operator between them. func And(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BillProduct(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.BillProduct) predicate.BillProduct { - return predicate.BillProduct(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.BillProduct(sql.NotPredicates(p)) } diff --git a/entgql/internal/todouuid/ent/billproduct_create.go b/entgql/internal/todouuid/ent/billproduct_create.go index 10fd33d12..0605a357c 100644 --- a/entgql/internal/todouuid/ent/billproduct_create.go +++ b/entgql/internal/todouuid/ent/billproduct_create.go @@ -74,7 +74,7 @@ func (bpc *BillProductCreate) Mutation() *BillProductMutation { // Save creates the BillProduct in the database. func (bpc *BillProductCreate) Save(ctx context.Context) (*BillProduct, error) { bpc.defaults() - return withHooks[*BillProduct, BillProductMutation](ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) + return withHooks(ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -171,11 +171,15 @@ func (bpc *BillProductCreate) createSpec() (*BillProduct, *sqlgraph.CreateSpec) // BillProductCreateBulk is the builder for creating many BillProduct entities in bulk. type BillProductCreateBulk struct { config + err error builders []*BillProductCreate } // Save creates the BillProduct entities in the database. func (bpcb *BillProductCreateBulk) Save(ctx context.Context) ([]*BillProduct, error) { + if bpcb.err != nil { + return nil, bpcb.err + } specs := make([]*sqlgraph.CreateSpec, len(bpcb.builders)) nodes := make([]*BillProduct, len(bpcb.builders)) mutators := make([]Mutator, len(bpcb.builders)) diff --git a/entgql/internal/todouuid/ent/billproduct_delete.go b/entgql/internal/todouuid/ent/billproduct_delete.go index 8a23432ca..5fb26a5e8 100644 --- a/entgql/internal/todouuid/ent/billproduct_delete.go +++ b/entgql/internal/todouuid/ent/billproduct_delete.go @@ -41,7 +41,7 @@ func (bpd *BillProductDelete) Where(ps ...predicate.BillProduct) *BillProductDel // Exec executes the deletion query and returns how many vertices were deleted. func (bpd *BillProductDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) + return withHooks(ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/billproduct_update.go b/entgql/internal/todouuid/ent/billproduct_update.go index 2522268f0..6ef33d9cc 100644 --- a/entgql/internal/todouuid/ent/billproduct_update.go +++ b/entgql/internal/todouuid/ent/billproduct_update.go @@ -47,12 +47,28 @@ func (bpu *BillProductUpdate) SetName(s string) *BillProductUpdate { return bpu } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableName(s *string) *BillProductUpdate { + if s != nil { + bpu.SetName(*s) + } + return bpu +} + // SetSku sets the "sku" field. func (bpu *BillProductUpdate) SetSku(s string) *BillProductUpdate { bpu.mutation.SetSku(s) return bpu } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableSku(s *string) *BillProductUpdate { + if s != nil { + bpu.SetSku(*s) + } + return bpu +} + // SetQuantity sets the "quantity" field. func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { bpu.mutation.ResetQuantity() @@ -60,6 +76,14 @@ func (bpu *BillProductUpdate) SetQuantity(u uint64) *BillProductUpdate { return bpu } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpu *BillProductUpdate) SetNillableQuantity(u *uint64) *BillProductUpdate { + if u != nil { + bpu.SetQuantity(*u) + } + return bpu +} + // AddQuantity adds u to the "quantity" field. func (bpu *BillProductUpdate) AddQuantity(u int64) *BillProductUpdate { bpu.mutation.AddQuantity(u) @@ -73,7 +97,7 @@ func (bpu *BillProductUpdate) Mutation() *BillProductMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (bpu *BillProductUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, BillProductMutation](ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) + return withHooks(ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -145,12 +169,28 @@ func (bpuo *BillProductUpdateOne) SetName(s string) *BillProductUpdateOne { return bpuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableName(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetName(*s) + } + return bpuo +} + // SetSku sets the "sku" field. func (bpuo *BillProductUpdateOne) SetSku(s string) *BillProductUpdateOne { bpuo.mutation.SetSku(s) return bpuo } +// SetNillableSku sets the "sku" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableSku(s *string) *BillProductUpdateOne { + if s != nil { + bpuo.SetSku(*s) + } + return bpuo +} + // SetQuantity sets the "quantity" field. func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { bpuo.mutation.ResetQuantity() @@ -158,6 +198,14 @@ func (bpuo *BillProductUpdateOne) SetQuantity(u uint64) *BillProductUpdateOne { return bpuo } +// SetNillableQuantity sets the "quantity" field if the given value is not nil. +func (bpuo *BillProductUpdateOne) SetNillableQuantity(u *uint64) *BillProductUpdateOne { + if u != nil { + bpuo.SetQuantity(*u) + } + return bpuo +} + // AddQuantity adds u to the "quantity" field. func (bpuo *BillProductUpdateOne) AddQuantity(u int64) *BillProductUpdateOne { bpuo.mutation.AddQuantity(u) @@ -184,7 +232,7 @@ func (bpuo *BillProductUpdateOne) Select(field string, fields ...string) *BillPr // Save executes the query and returns the updated BillProduct entity. func (bpuo *BillProductUpdateOne) Save(ctx context.Context) (*BillProduct, error) { - return withHooks[*BillProduct, BillProductMutation](ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) + return withHooks(ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/category/where.go b/entgql/internal/todouuid/ent/category/where.go index 7af926c2f..1f3dd26dd 100644 --- a/entgql/internal/todouuid/ent/category/where.go +++ b/entgql/internal/todouuid/ent/category/where.go @@ -409,32 +409,15 @@ func HasSubCategoriesWith(preds ...predicate.Category) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entgql/internal/todouuid/ent/category_create.go b/entgql/internal/todouuid/ent/category_create.go index 111b12e97..0ff102496 100644 --- a/entgql/internal/todouuid/ent/category_create.go +++ b/entgql/internal/todouuid/ent/category_create.go @@ -147,7 +147,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { cc.defaults() - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -299,11 +299,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entgql/internal/todouuid/ent/category_delete.go b/entgql/internal/todouuid/ent/category_delete.go index a7410eea7..4ab41475f 100644 --- a/entgql/internal/todouuid/ent/category_delete.go +++ b/entgql/internal/todouuid/ent/category_delete.go @@ -41,7 +41,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/category_update.go b/entgql/internal/todouuid/ent/category_update.go index 96e5dce24..62c4768e1 100644 --- a/entgql/internal/todouuid/ent/category_update.go +++ b/entgql/internal/todouuid/ent/category_update.go @@ -52,12 +52,28 @@ func (cu *CategoryUpdate) SetText(s string) *CategoryUpdate { return cu } +// SetNillableText sets the "text" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableText(s *string) *CategoryUpdate { + if s != nil { + cu.SetText(*s) + } + return cu +} + // SetStatus sets the "status" field. func (cu *CategoryUpdate) SetStatus(c category.Status) *CategoryUpdate { cu.mutation.SetStatus(c) return cu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableStatus(c *category.Status) *CategoryUpdate { + if c != nil { + cu.SetStatus(*c) + } + return cu +} + // SetConfig sets the "config" field. func (cu *CategoryUpdate) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdate { cu.mutation.SetConfig(sc) @@ -233,7 +249,7 @@ func (cu *CategoryUpdate) RemoveSubCategories(c ...*Category) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -448,12 +464,28 @@ func (cuo *CategoryUpdateOne) SetText(s string) *CategoryUpdateOne { return cuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableText(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetText(*s) + } + return cuo +} + // SetStatus sets the "status" field. func (cuo *CategoryUpdateOne) SetStatus(c category.Status) *CategoryUpdateOne { cuo.mutation.SetStatus(c) return cuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableStatus(c *category.Status) *CategoryUpdateOne { + if c != nil { + cuo.SetStatus(*c) + } + return cuo +} + // SetConfig sets the "config" field. func (cuo *CategoryUpdateOne) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdateOne { cuo.mutation.SetConfig(sc) @@ -642,7 +674,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/client.go b/entgql/internal/todouuid/ent/client.go index 9efdeeca9..5f777d486 100644 --- a/entgql/internal/todouuid/ent/client.go +++ b/entgql/internal/todouuid/ent/client.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entgql/internal/todouuid/ent/migrate" "entgo.io/ent" @@ -144,11 +145,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -292,6 +296,21 @@ func (c *BillProductClient) CreateBulk(builders ...*BillProductCreate) *BillProd return &BillProductCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *BillProductClient) MapCreateBulk(slice any, setFunc func(*BillProductCreate, int)) *BillProductCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &BillProductCreateBulk{err: fmt.Errorf("calling to BillProductClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*BillProductCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &BillProductCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for BillProduct. func (c *BillProductClient) Update() *BillProductUpdate { mutation := newBillProductMutation(c.config, OpUpdate) @@ -410,6 +429,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -560,6 +594,21 @@ func (c *FriendshipClient) CreateBulk(builders ...*FriendshipCreate) *Friendship return &FriendshipCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *FriendshipClient) MapCreateBulk(slice any, setFunc func(*FriendshipCreate, int)) *FriendshipCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &FriendshipCreateBulk{err: fmt.Errorf("calling to FriendshipClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*FriendshipCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &FriendshipCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Friendship. func (c *FriendshipClient) Update() *FriendshipUpdate { mutation := newFriendshipMutation(c.config, OpUpdate) @@ -710,6 +759,21 @@ func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { return &GroupCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Group. func (c *GroupClient) Update() *GroupUpdate { mutation := newGroupMutation(c.config, OpUpdate) @@ -844,6 +908,21 @@ func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk { return &TodoCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TodoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TodoCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Todo. func (c *TodoClient) Update() *TodoUpdate { mutation := newTodoMutation(c.config, OpUpdate) @@ -1026,6 +1105,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) @@ -1192,6 +1286,21 @@ func (c *VerySecretClient) CreateBulk(builders ...*VerySecretCreate) *VerySecret return &VerySecretCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *VerySecretClient) MapCreateBulk(slice any, setFunc func(*VerySecretCreate, int)) *VerySecretCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &VerySecretCreateBulk{err: fmt.Errorf("calling to VerySecretClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*VerySecretCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &VerySecretCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for VerySecret. func (c *VerySecretClient) Update() *VerySecretUpdate { mutation := newVerySecretMutation(c.config, OpUpdate) diff --git a/entgql/internal/todouuid/ent/friendship/where.go b/entgql/internal/todouuid/ent/friendship/where.go index 923cf1f77..0d9cc3f83 100644 --- a/entgql/internal/todouuid/ent/friendship/where.go +++ b/entgql/internal/todouuid/ent/friendship/where.go @@ -213,32 +213,15 @@ func HasFriendWith(preds ...predicate.User) predicate.Friendship { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Friendship(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Friendship) predicate.Friendship { - return predicate.Friendship(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Friendship(sql.NotPredicates(p)) } diff --git a/entgql/internal/todouuid/ent/friendship_create.go b/entgql/internal/todouuid/ent/friendship_create.go index 18dac8b8e..01a2fc5de 100644 --- a/entgql/internal/todouuid/ent/friendship_create.go +++ b/entgql/internal/todouuid/ent/friendship_create.go @@ -94,7 +94,7 @@ func (fc *FriendshipCreate) Mutation() *FriendshipMutation { // Save creates the Friendship in the database. func (fc *FriendshipCreate) Save(ctx context.Context) (*Friendship, error) { fc.defaults() - return withHooks[*Friendship, FriendshipMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) + return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -227,11 +227,15 @@ func (fc *FriendshipCreate) createSpec() (*Friendship, *sqlgraph.CreateSpec) { // FriendshipCreateBulk is the builder for creating many Friendship entities in bulk. type FriendshipCreateBulk struct { config + err error builders []*FriendshipCreate } // Save creates the Friendship entities in the database. func (fcb *FriendshipCreateBulk) Save(ctx context.Context) ([]*Friendship, error) { + if fcb.err != nil { + return nil, fcb.err + } specs := make([]*sqlgraph.CreateSpec, len(fcb.builders)) nodes := make([]*Friendship, len(fcb.builders)) mutators := make([]Mutator, len(fcb.builders)) diff --git a/entgql/internal/todouuid/ent/friendship_delete.go b/entgql/internal/todouuid/ent/friendship_delete.go index acad745c3..e720bc5c0 100644 --- a/entgql/internal/todouuid/ent/friendship_delete.go +++ b/entgql/internal/todouuid/ent/friendship_delete.go @@ -41,7 +41,7 @@ func (fd *FriendshipDelete) Where(ps ...predicate.Friendship) *FriendshipDelete // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FriendshipDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) + return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/friendship_update.go b/entgql/internal/todouuid/ent/friendship_update.go index 8818d5023..a6c6b4734 100644 --- a/entgql/internal/todouuid/ent/friendship_update.go +++ b/entgql/internal/todouuid/ent/friendship_update.go @@ -64,12 +64,28 @@ func (fu *FriendshipUpdate) SetUserID(u uuid.UUID) *FriendshipUpdate { return fu } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableUserID(u *uuid.UUID) *FriendshipUpdate { + if u != nil { + fu.SetUserID(*u) + } + return fu +} + // SetFriendID sets the "friend_id" field. func (fu *FriendshipUpdate) SetFriendID(u uuid.UUID) *FriendshipUpdate { fu.mutation.SetFriendID(u) return fu } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fu *FriendshipUpdate) SetNillableFriendID(u *uuid.UUID) *FriendshipUpdate { + if u != nil { + fu.SetFriendID(*u) + } + return fu +} + // SetUser sets the "user" edge to the User entity. func (fu *FriendshipUpdate) SetUser(u *User) *FriendshipUpdate { return fu.SetUserID(u.ID) @@ -99,7 +115,7 @@ func (fu *FriendshipUpdate) ClearFriend() *FriendshipUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FriendshipUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, FriendshipMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) + return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -248,12 +264,28 @@ func (fuo *FriendshipUpdateOne) SetUserID(u uuid.UUID) *FriendshipUpdateOne { return fuo } +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableUserID(u *uuid.UUID) *FriendshipUpdateOne { + if u != nil { + fuo.SetUserID(*u) + } + return fuo +} + // SetFriendID sets the "friend_id" field. func (fuo *FriendshipUpdateOne) SetFriendID(u uuid.UUID) *FriendshipUpdateOne { fuo.mutation.SetFriendID(u) return fuo } +// SetNillableFriendID sets the "friend_id" field if the given value is not nil. +func (fuo *FriendshipUpdateOne) SetNillableFriendID(u *uuid.UUID) *FriendshipUpdateOne { + if u != nil { + fuo.SetFriendID(*u) + } + return fuo +} + // SetUser sets the "user" edge to the User entity. func (fuo *FriendshipUpdateOne) SetUser(u *User) *FriendshipUpdateOne { return fuo.SetUserID(u.ID) @@ -296,7 +328,7 @@ func (fuo *FriendshipUpdateOne) Select(field string, fields ...string) *Friendsh // Save executes the query and returns the updated Friendship entity. func (fuo *FriendshipUpdateOne) Save(ctx context.Context) (*Friendship, error) { - return withHooks[*Friendship, FriendshipMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) + return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/group/where.go b/entgql/internal/todouuid/ent/group/where.go index 1e5898a91..9d04941e6 100644 --- a/entgql/internal/todouuid/ent/group/where.go +++ b/entgql/internal/todouuid/ent/group/where.go @@ -163,32 +163,15 @@ func HasUsersWith(preds ...predicate.User) predicate.Group { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Group(sql.NotPredicates(p)) } diff --git a/entgql/internal/todouuid/ent/group_create.go b/entgql/internal/todouuid/ent/group_create.go index 3970e859a..749cb26d4 100644 --- a/entgql/internal/todouuid/ent/group_create.go +++ b/entgql/internal/todouuid/ent/group_create.go @@ -86,7 +86,7 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { gc.defaults() - return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) + return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -189,11 +189,15 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { // GroupCreateBulk is the builder for creating many Group entities in bulk. type GroupCreateBulk struct { config + err error builders []*GroupCreate } // Save creates the Group entities in the database. func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { + if gcb.err != nil { + return nil, gcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gcb.builders)) nodes := make([]*Group, len(gcb.builders)) mutators := make([]Mutator, len(gcb.builders)) diff --git a/entgql/internal/todouuid/ent/group_delete.go b/entgql/internal/todouuid/ent/group_delete.go index ea920c60a..231bee1db 100644 --- a/entgql/internal/todouuid/ent/group_delete.go +++ b/entgql/internal/todouuid/ent/group_delete.go @@ -41,7 +41,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) + return withHooks(ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/group_update.go b/entgql/internal/todouuid/ent/group_update.go index 1387c9111..49f700d45 100644 --- a/entgql/internal/todouuid/ent/group_update.go +++ b/entgql/internal/todouuid/ent/group_update.go @@ -100,7 +100,7 @@ func (gu *GroupUpdate) RemoveUsers(u ...*User) *GroupUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) + return withHooks(ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -272,7 +272,7 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { - return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) + return withHooks(ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/mutation.go b/entgql/internal/todouuid/ent/mutation.go index f608ba0aa..6ee345ecd 100644 --- a/entgql/internal/todouuid/ent/mutation.go +++ b/entgql/internal/todouuid/ent/mutation.go @@ -1782,6 +1782,7 @@ func (m *FriendshipMutation) ResetFriendID() { // ClearUser clears the "user" edge to the User entity. func (m *FriendshipMutation) ClearUser() { m.cleareduser = true + m.clearedFields[friendship.FieldUserID] = struct{}{} } // UserCleared reports if the "user" edge to the User entity was cleared. @@ -1808,6 +1809,7 @@ func (m *FriendshipMutation) ResetUser() { // ClearFriend clears the "friend" edge to the User entity. func (m *FriendshipMutation) ClearFriend() { m.clearedfriend = true + m.clearedFields[friendship.FieldFriendID] = struct{}{} } // FriendCleared reports if the "friend" edge to the User entity was cleared. @@ -3186,6 +3188,7 @@ func (m *TodoMutation) ResetChildren() { // ClearCategory clears the "category" edge to the Category entity. func (m *TodoMutation) ClearCategory() { m.clearedcategory = true + m.clearedFields[todo.FieldCategoryID] = struct{}{} } // CategoryCleared reports if the "category" edge to the Category entity was cleared. diff --git a/entgql/internal/todouuid/ent/runtime/runtime.go b/entgql/internal/todouuid/ent/runtime/runtime.go index 384887c2b..3514c21b1 100644 --- a/entgql/internal/todouuid/ent/runtime/runtime.go +++ b/entgql/internal/todouuid/ent/runtime/runtime.go @@ -19,6 +19,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entgql/internal/todouuid/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entgql/internal/todouuid/ent/todo/where.go b/entgql/internal/todouuid/ent/todo/where.go index 7ee947a4f..9449e7bbb 100644 --- a/entgql/internal/todouuid/ent/todo/where.go +++ b/entgql/internal/todouuid/ent/todo/where.go @@ -464,32 +464,15 @@ func HasSecretWith(preds ...predicate.VerySecret) predicate.Todo { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Todo(sql.NotPredicates(p)) } diff --git a/entgql/internal/todouuid/ent/todo_create.go b/entgql/internal/todouuid/ent/todo_create.go index c2aa168e1..20a4bda27 100644 --- a/entgql/internal/todouuid/ent/todo_create.go +++ b/entgql/internal/todouuid/ent/todo_create.go @@ -196,7 +196,7 @@ func (tc *TodoCreate) Mutation() *TodoMutation { // Save creates the Todo in the database. func (tc *TodoCreate) Save(ctx context.Context) (*Todo, error) { tc.defaults() - return withHooks[*Todo, TodoMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -401,11 +401,15 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { // TodoCreateBulk is the builder for creating many Todo entities in bulk. type TodoCreateBulk struct { config + err error builders []*TodoCreate } // Save creates the Todo entities in the database. func (tcb *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Todo, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) diff --git a/entgql/internal/todouuid/ent/todo_delete.go b/entgql/internal/todouuid/ent/todo_delete.go index dbd18536c..8593ec147 100644 --- a/entgql/internal/todouuid/ent/todo_delete.go +++ b/entgql/internal/todouuid/ent/todo_delete.go @@ -41,7 +41,7 @@ func (td *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TodoDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/todo_update.go b/entgql/internal/todouuid/ent/todo_update.go index 9fae2af32..097db002f 100644 --- a/entgql/internal/todouuid/ent/todo_update.go +++ b/entgql/internal/todouuid/ent/todo_update.go @@ -51,6 +51,14 @@ func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate { return tu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableStatus(t *todo.Status) *TodoUpdate { + if t != nil { + tu.SetStatus(*t) + } + return tu +} + // SetPriority sets the "priority" field. func (tu *TodoUpdate) SetPriority(i int) *TodoUpdate { tu.mutation.ResetPriority() @@ -78,6 +86,14 @@ func (tu *TodoUpdate) SetText(s string) *TodoUpdate { return tu } +// SetNillableText sets the "text" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { + if s != nil { + tu.SetText(*s) + } + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -231,7 +247,7 @@ func (tu *TodoUpdate) ClearSecret() *TodoUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TodoUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -458,6 +474,14 @@ func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne { return tuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableStatus(t *todo.Status) *TodoUpdateOne { + if t != nil { + tuo.SetStatus(*t) + } + return tuo +} + // SetPriority sets the "priority" field. func (tuo *TodoUpdateOne) SetPriority(i int) *TodoUpdateOne { tuo.mutation.ResetPriority() @@ -485,6 +509,14 @@ func (tuo *TodoUpdateOne) SetText(s string) *TodoUpdateOne { return tuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetText(*s) + } + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -651,7 +683,7 @@ func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne // Save executes the query and returns the updated Todo entity. func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { - return withHooks[*Todo, TodoMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/user/where.go b/entgql/internal/todouuid/ent/user/where.go index a11fd55a4..cd68b540d 100644 --- a/entgql/internal/todouuid/ent/user/where.go +++ b/entgql/internal/todouuid/ent/user/where.go @@ -344,32 +344,15 @@ func HasFriendshipsWith(preds ...predicate.Friendship) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entgql/internal/todouuid/ent/user_create.go b/entgql/internal/todouuid/ent/user_create.go index ff3b4880a..52f91bc78 100644 --- a/entgql/internal/todouuid/ent/user_create.go +++ b/entgql/internal/todouuid/ent/user_create.go @@ -157,7 +157,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { uc.defaults() - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -325,11 +325,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entgql/internal/todouuid/ent/user_delete.go b/entgql/internal/todouuid/ent/user_delete.go index cf9dac2d7..63269a51f 100644 --- a/entgql/internal/todouuid/ent/user_delete.go +++ b/entgql/internal/todouuid/ent/user_delete.go @@ -41,7 +41,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/user_update.go b/entgql/internal/todouuid/ent/user_update.go index 8afe22531..7424ef8ed 100644 --- a/entgql/internal/todouuid/ent/user_update.go +++ b/entgql/internal/todouuid/ent/user_update.go @@ -225,7 +225,7 @@ func (uu *UserUpdate) RemoveFriendships(f ...*Friendship) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -650,7 +650,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/verysecret/where.go b/entgql/internal/todouuid/ent/verysecret/where.go index 661db7d58..36ca58408 100644 --- a/entgql/internal/todouuid/ent/verysecret/where.go +++ b/entgql/internal/todouuid/ent/verysecret/where.go @@ -139,32 +139,15 @@ func PasswordContainsFold(v string) predicate.VerySecret { // And groups predicates with the AND operator between them. func And(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.VerySecret(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.VerySecret) predicate.VerySecret { - return predicate.VerySecret(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.VerySecret(sql.NotPredicates(p)) } diff --git a/entgql/internal/todouuid/ent/verysecret_create.go b/entgql/internal/todouuid/ent/verysecret_create.go index 400d17ab5..5131d094d 100644 --- a/entgql/internal/todouuid/ent/verysecret_create.go +++ b/entgql/internal/todouuid/ent/verysecret_create.go @@ -62,7 +62,7 @@ func (vsc *VerySecretCreate) Mutation() *VerySecretMutation { // Save creates the VerySecret in the database. func (vsc *VerySecretCreate) Save(ctx context.Context) (*VerySecret, error) { vsc.defaults() - return withHooks[*VerySecret, VerySecretMutation](ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) + return withHooks(ctx, vsc.sqlSave, vsc.mutation, vsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -145,11 +145,15 @@ func (vsc *VerySecretCreate) createSpec() (*VerySecret, *sqlgraph.CreateSpec) { // VerySecretCreateBulk is the builder for creating many VerySecret entities in bulk. type VerySecretCreateBulk struct { config + err error builders []*VerySecretCreate } // Save creates the VerySecret entities in the database. func (vscb *VerySecretCreateBulk) Save(ctx context.Context) ([]*VerySecret, error) { + if vscb.err != nil { + return nil, vscb.err + } specs := make([]*sqlgraph.CreateSpec, len(vscb.builders)) nodes := make([]*VerySecret, len(vscb.builders)) mutators := make([]Mutator, len(vscb.builders)) diff --git a/entgql/internal/todouuid/ent/verysecret_delete.go b/entgql/internal/todouuid/ent/verysecret_delete.go index 0f6ef08e7..155b7a6b0 100644 --- a/entgql/internal/todouuid/ent/verysecret_delete.go +++ b/entgql/internal/todouuid/ent/verysecret_delete.go @@ -41,7 +41,7 @@ func (vsd *VerySecretDelete) Where(ps ...predicate.VerySecret) *VerySecretDelete // Exec executes the deletion query and returns how many vertices were deleted. func (vsd *VerySecretDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) + return withHooks(ctx, vsd.sqlExec, vsd.mutation, vsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entgql/internal/todouuid/ent/verysecret_update.go b/entgql/internal/todouuid/ent/verysecret_update.go index dead078a9..27167b72c 100644 --- a/entgql/internal/todouuid/ent/verysecret_update.go +++ b/entgql/internal/todouuid/ent/verysecret_update.go @@ -47,6 +47,14 @@ func (vsu *VerySecretUpdate) SetPassword(s string) *VerySecretUpdate { return vsu } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsu *VerySecretUpdate) SetNillablePassword(s *string) *VerySecretUpdate { + if s != nil { + vsu.SetPassword(*s) + } + return vsu +} + // Mutation returns the VerySecretMutation object of the builder. func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { return vsu.mutation @@ -54,7 +62,7 @@ func (vsu *VerySecretUpdate) Mutation() *VerySecretMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (vsu *VerySecretUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, VerySecretMutation](ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) + return withHooks(ctx, vsu.sqlSave, vsu.mutation, vsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -117,6 +125,14 @@ func (vsuo *VerySecretUpdateOne) SetPassword(s string) *VerySecretUpdateOne { return vsuo } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (vsuo *VerySecretUpdateOne) SetNillablePassword(s *string) *VerySecretUpdateOne { + if s != nil { + vsuo.SetPassword(*s) + } + return vsuo +} + // Mutation returns the VerySecretMutation object of the builder. func (vsuo *VerySecretUpdateOne) Mutation() *VerySecretMutation { return vsuo.mutation @@ -137,7 +153,7 @@ func (vsuo *VerySecretUpdateOne) Select(field string, fields ...string) *VerySec // Save executes the query and returns the updated VerySecret entity. func (vsuo *VerySecretUpdateOne) Save(ctx context.Context) (*VerySecret, error) { - return withHooks[*VerySecret, VerySecretMutation](ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) + return withHooks(ctx, vsuo.sqlSave, vsuo.mutation, vsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entgql/internal/todouuid/server/server.go b/entgql/internal/todouuid/server/server.go index 159b8ec33..f5d7f9034 100644 --- a/entgql/internal/todouuid/server/server.go +++ b/entgql/internal/todouuid/server/server.go @@ -16,6 +16,7 @@ package main import ( "context" "net/http" + "time" "entgo.io/contrib/entgql" todo "entgo.io/contrib/entgql/internal/todouuid" @@ -61,7 +62,11 @@ func main() { http.Handle("/query", srv) log.Info("listening on", zap.String("address", cli.Addr)) - if err := http.ListenAndServe(cli.Addr, nil); err != nil { + server := &http.Server{ + Addr: cli.Addr, + ReadHeaderTimeout: 30 * time.Second, + } + if err := server.ListenAndServe(); err != nil { log.Error("http server terminated", zap.Error(err)) } } diff --git a/entoas/internal/cycle/client.go b/entoas/internal/cycle/client.go index 5cbeb5a87..53a9a456b 100644 --- a/entoas/internal/cycle/client.go +++ b/entoas/internal/cycle/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entoas/internal/cycle/migrate" "entgo.io/ent" @@ -105,11 +106,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("cycle: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("cycle: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -221,6 +225,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/entoas/internal/cycle/runtime/runtime.go b/entoas/internal/cycle/runtime/runtime.go index 780e60b13..8f17fc6a6 100644 --- a/entoas/internal/cycle/runtime/runtime.go +++ b/entoas/internal/cycle/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entoas/internal/cycle/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entoas/internal/cycle/user/where.go b/entoas/internal/cycle/user/where.go index b89c317a7..994776e74 100644 --- a/entoas/internal/cycle/user/where.go +++ b/entoas/internal/cycle/user/where.go @@ -170,32 +170,15 @@ func HasChildrenWith(preds ...predicate.User) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entoas/internal/cycle/user_create.go b/entoas/internal/cycle/user_create.go index d28c7c66c..d2577f3c2 100644 --- a/entoas/internal/cycle/user_create.go +++ b/entoas/internal/cycle/user_create.go @@ -104,7 +104,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -244,11 +244,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entoas/internal/cycle/user_delete.go b/entoas/internal/cycle/user_delete.go index 67e3ed79f..05a0b9937 100644 --- a/entoas/internal/cycle/user_delete.go +++ b/entoas/internal/cycle/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/cycle/user_update.go b/entoas/internal/cycle/user_update.go index 3fdea89de..8f4603ead 100644 --- a/entoas/internal/cycle/user_update.go +++ b/entoas/internal/cycle/user_update.go @@ -203,7 +203,7 @@ func (uu *UserUpdate) RemoveChildren(u ...*User) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -655,7 +655,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entoas/internal/oastypes/client.go b/entoas/internal/oastypes/client.go index af2cb2130..c7dff594f 100644 --- a/entoas/internal/oastypes/client.go +++ b/entoas/internal/oastypes/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entoas/internal/oastypes/migrate" "entgo.io/ent" @@ -104,11 +105,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("oastypes: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("oastypes: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -220,6 +224,21 @@ func (c *OASTypesClient) CreateBulk(builders ...*OASTypesCreate) *OASTypesCreate return &OASTypesCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *OASTypesClient) MapCreateBulk(slice any, setFunc func(*OASTypesCreate, int)) *OASTypesCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &OASTypesCreateBulk{err: fmt.Errorf("calling to OASTypesClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*OASTypesCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &OASTypesCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for OASTypes. func (c *OASTypesClient) Update() *OASTypesUpdate { mutation := newOASTypesMutation(c.config, OpUpdate) diff --git a/entoas/internal/oastypes/oastypes/where.go b/entoas/internal/oastypes/oastypes/where.go index f368057d7..58c740ae6 100644 --- a/entoas/internal/oastypes/oastypes/where.go +++ b/entoas/internal/oastypes/oastypes/where.go @@ -1108,32 +1108,15 @@ func OptionalAndNillableNotNil() predicate.OASTypes { // And groups predicates with the AND operator between them. func And(predicates ...predicate.OASTypes) predicate.OASTypes { - return predicate.OASTypes(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.OASTypes(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.OASTypes) predicate.OASTypes { - return predicate.OASTypes(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.OASTypes(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.OASTypes) predicate.OASTypes { - return predicate.OASTypes(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.OASTypes(sql.NotPredicates(p)) } diff --git a/entoas/internal/oastypes/oastypes_create.go b/entoas/internal/oastypes/oastypes_create.go index 5e4699aa0..8ad55cb81 100644 --- a/entoas/internal/oastypes/oastypes_create.go +++ b/entoas/internal/oastypes/oastypes_create.go @@ -230,7 +230,7 @@ func (otc *OASTypesCreate) Mutation() *OASTypesMutation { // Save creates the OASTypes in the database. func (otc *OASTypesCreate) Save(ctx context.Context) (*OASTypes, error) { otc.defaults() - return withHooks[*OASTypes, OASTypesMutation](ctx, otc.sqlSave, otc.mutation, otc.hooks) + return withHooks(ctx, otc.sqlSave, otc.mutation, otc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -503,11 +503,15 @@ func (otc *OASTypesCreate) createSpec() (*OASTypes, *sqlgraph.CreateSpec) { // OASTypesCreateBulk is the builder for creating many OASTypes entities in bulk. type OASTypesCreateBulk struct { config + err error builders []*OASTypesCreate } // Save creates the OASTypes entities in the database. func (otcb *OASTypesCreateBulk) Save(ctx context.Context) ([]*OASTypes, error) { + if otcb.err != nil { + return nil, otcb.err + } specs := make([]*sqlgraph.CreateSpec, len(otcb.builders)) nodes := make([]*OASTypes, len(otcb.builders)) mutators := make([]Mutator, len(otcb.builders)) diff --git a/entoas/internal/oastypes/oastypes_delete.go b/entoas/internal/oastypes/oastypes_delete.go index 698546d6b..8497c85a3 100644 --- a/entoas/internal/oastypes/oastypes_delete.go +++ b/entoas/internal/oastypes/oastypes_delete.go @@ -27,7 +27,7 @@ func (otd *OASTypesDelete) Where(ps ...predicate.OASTypes) *OASTypesDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (otd *OASTypesDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, OASTypesMutation](ctx, otd.sqlExec, otd.mutation, otd.hooks) + return withHooks(ctx, otd.sqlExec, otd.mutation, otd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/oastypes/oastypes_update.go b/entoas/internal/oastypes/oastypes_update.go index d02b456a0..0146cc8f7 100644 --- a/entoas/internal/oastypes/oastypes_update.go +++ b/entoas/internal/oastypes/oastypes_update.go @@ -40,6 +40,14 @@ func (otu *OASTypesUpdate) SetInt(i int) *OASTypesUpdate { return otu } +// SetNillableInt sets the "int" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableInt(i *int) *OASTypesUpdate { + if i != nil { + otu.SetInt(*i) + } + return otu +} + // AddInt adds i to the "int" field. func (otu *OASTypesUpdate) AddInt(i int) *OASTypesUpdate { otu.mutation.AddInt(i) @@ -53,6 +61,14 @@ func (otu *OASTypesUpdate) SetInt8(i int8) *OASTypesUpdate { return otu } +// SetNillableInt8 sets the "int8" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableInt8(i *int8) *OASTypesUpdate { + if i != nil { + otu.SetInt8(*i) + } + return otu +} + // AddInt8 adds i to the "int8" field. func (otu *OASTypesUpdate) AddInt8(i int8) *OASTypesUpdate { otu.mutation.AddInt8(i) @@ -66,6 +82,14 @@ func (otu *OASTypesUpdate) SetInt16(i int16) *OASTypesUpdate { return otu } +// SetNillableInt16 sets the "int16" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableInt16(i *int16) *OASTypesUpdate { + if i != nil { + otu.SetInt16(*i) + } + return otu +} + // AddInt16 adds i to the "int16" field. func (otu *OASTypesUpdate) AddInt16(i int16) *OASTypesUpdate { otu.mutation.AddInt16(i) @@ -79,6 +103,14 @@ func (otu *OASTypesUpdate) SetInt32(i int32) *OASTypesUpdate { return otu } +// SetNillableInt32 sets the "int32" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableInt32(i *int32) *OASTypesUpdate { + if i != nil { + otu.SetInt32(*i) + } + return otu +} + // AddInt32 adds i to the "int32" field. func (otu *OASTypesUpdate) AddInt32(i int32) *OASTypesUpdate { otu.mutation.AddInt32(i) @@ -92,6 +124,14 @@ func (otu *OASTypesUpdate) SetInt64(i int64) *OASTypesUpdate { return otu } +// SetNillableInt64 sets the "int64" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableInt64(i *int64) *OASTypesUpdate { + if i != nil { + otu.SetInt64(*i) + } + return otu +} + // AddInt64 adds i to the "int64" field. func (otu *OASTypesUpdate) AddInt64(i int64) *OASTypesUpdate { otu.mutation.AddInt64(i) @@ -105,6 +145,14 @@ func (otu *OASTypesUpdate) SetUint(u uint) *OASTypesUpdate { return otu } +// SetNillableUint sets the "uint" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableUint(u *uint) *OASTypesUpdate { + if u != nil { + otu.SetUint(*u) + } + return otu +} + // AddUint adds u to the "uint" field. func (otu *OASTypesUpdate) AddUint(u int) *OASTypesUpdate { otu.mutation.AddUint(u) @@ -118,6 +166,14 @@ func (otu *OASTypesUpdate) SetUint8(u uint8) *OASTypesUpdate { return otu } +// SetNillableUint8 sets the "uint8" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableUint8(u *uint8) *OASTypesUpdate { + if u != nil { + otu.SetUint8(*u) + } + return otu +} + // AddUint8 adds u to the "uint8" field. func (otu *OASTypesUpdate) AddUint8(u int8) *OASTypesUpdate { otu.mutation.AddUint8(u) @@ -131,6 +187,14 @@ func (otu *OASTypesUpdate) SetUint16(u uint16) *OASTypesUpdate { return otu } +// SetNillableUint16 sets the "uint16" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableUint16(u *uint16) *OASTypesUpdate { + if u != nil { + otu.SetUint16(*u) + } + return otu +} + // AddUint16 adds u to the "uint16" field. func (otu *OASTypesUpdate) AddUint16(u int16) *OASTypesUpdate { otu.mutation.AddUint16(u) @@ -144,6 +208,14 @@ func (otu *OASTypesUpdate) SetUint32(u uint32) *OASTypesUpdate { return otu } +// SetNillableUint32 sets the "uint32" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableUint32(u *uint32) *OASTypesUpdate { + if u != nil { + otu.SetUint32(*u) + } + return otu +} + // AddUint32 adds u to the "uint32" field. func (otu *OASTypesUpdate) AddUint32(u int32) *OASTypesUpdate { otu.mutation.AddUint32(u) @@ -157,6 +229,14 @@ func (otu *OASTypesUpdate) SetUint64(u uint64) *OASTypesUpdate { return otu } +// SetNillableUint64 sets the "uint64" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableUint64(u *uint64) *OASTypesUpdate { + if u != nil { + otu.SetUint64(*u) + } + return otu +} + // AddUint64 adds u to the "uint64" field. func (otu *OASTypesUpdate) AddUint64(u int64) *OASTypesUpdate { otu.mutation.AddUint64(u) @@ -170,6 +250,14 @@ func (otu *OASTypesUpdate) SetFloat32(f float32) *OASTypesUpdate { return otu } +// SetNillableFloat32 sets the "float32" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableFloat32(f *float32) *OASTypesUpdate { + if f != nil { + otu.SetFloat32(*f) + } + return otu +} + // AddFloat32 adds f to the "float32" field. func (otu *OASTypesUpdate) AddFloat32(f float32) *OASTypesUpdate { otu.mutation.AddFloat32(f) @@ -183,6 +271,14 @@ func (otu *OASTypesUpdate) SetFloat64(f float64) *OASTypesUpdate { return otu } +// SetNillableFloat64 sets the "float64" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableFloat64(f *float64) *OASTypesUpdate { + if f != nil { + otu.SetFloat64(*f) + } + return otu +} + // AddFloat64 adds f to the "float64" field. func (otu *OASTypesUpdate) AddFloat64(f float64) *OASTypesUpdate { otu.mutation.AddFloat64(f) @@ -195,12 +291,28 @@ func (otu *OASTypesUpdate) SetStringField(s string) *OASTypesUpdate { return otu } +// SetNillableStringField sets the "string_field" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableStringField(s *string) *OASTypesUpdate { + if s != nil { + otu.SetStringField(*s) + } + return otu +} + // SetBool sets the "bool" field. func (otu *OASTypesUpdate) SetBool(b bool) *OASTypesUpdate { otu.mutation.SetBool(b) return otu } +// SetNillableBool sets the "bool" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableBool(b *bool) *OASTypesUpdate { + if b != nil { + otu.SetBool(*b) + } + return otu +} + // SetUUID sets the "uuid" field. func (otu *OASTypesUpdate) SetUUID(u uuid.UUID) *OASTypesUpdate { otu.mutation.SetUUID(u) @@ -221,18 +333,42 @@ func (otu *OASTypesUpdate) SetTime(t time.Time) *OASTypesUpdate { return otu } +// SetNillableTime sets the "time" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableTime(t *time.Time) *OASTypesUpdate { + if t != nil { + otu.SetTime(*t) + } + return otu +} + // SetText sets the "text" field. func (otu *OASTypesUpdate) SetText(s string) *OASTypesUpdate { otu.mutation.SetText(s) return otu } +// SetNillableText sets the "text" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableText(s *string) *OASTypesUpdate { + if s != nil { + otu.SetText(*s) + } + return otu +} + // SetState sets the "state" field. func (otu *OASTypesUpdate) SetState(o oastypes.State) *OASTypesUpdate { otu.mutation.SetState(o) return otu } +// SetNillableState sets the "state" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableState(o *oastypes.State) *OASTypesUpdate { + if o != nil { + otu.SetState(*o) + } + return otu +} + // SetStrings sets the "strings" field. func (otu *OASTypesUpdate) SetStrings(s []string) *OASTypesUpdate { otu.mutation.SetStrings(s) @@ -305,6 +441,14 @@ func (otu *OASTypesUpdate) SetJSONObj(u url.URL) *OASTypesUpdate { return otu } +// SetNillableJSONObj sets the "json_obj" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableJSONObj(u *url.URL) *OASTypesUpdate { + if u != nil { + otu.SetJSONObj(*u) + } + return otu +} + // SetOther sets the "other" field. func (otu *OASTypesUpdate) SetOther(s *schema.Link) *OASTypesUpdate { otu.mutation.SetOther(s) @@ -345,6 +489,14 @@ func (otu *OASTypesUpdate) SetNillable(i int) *OASTypesUpdate { return otu } +// SetNillableNillable sets the "nillable" field if the given value is not nil. +func (otu *OASTypesUpdate) SetNillableNillable(i *int) *OASTypesUpdate { + if i != nil { + otu.SetNillable(*i) + } + return otu +} + // AddNillable adds i to the "nillable" field. func (otu *OASTypesUpdate) AddNillable(i int) *OASTypesUpdate { otu.mutation.AddNillable(i) @@ -385,7 +537,7 @@ func (otu *OASTypesUpdate) Mutation() *OASTypesMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (otu *OASTypesUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, OASTypesMutation](ctx, otu.sqlSave, otu.mutation, otu.hooks) + return withHooks(ctx, otu.sqlSave, otu.mutation, otu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -622,6 +774,14 @@ func (otuo *OASTypesUpdateOne) SetInt(i int) *OASTypesUpdateOne { return otuo } +// SetNillableInt sets the "int" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableInt(i *int) *OASTypesUpdateOne { + if i != nil { + otuo.SetInt(*i) + } + return otuo +} + // AddInt adds i to the "int" field. func (otuo *OASTypesUpdateOne) AddInt(i int) *OASTypesUpdateOne { otuo.mutation.AddInt(i) @@ -635,6 +795,14 @@ func (otuo *OASTypesUpdateOne) SetInt8(i int8) *OASTypesUpdateOne { return otuo } +// SetNillableInt8 sets the "int8" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableInt8(i *int8) *OASTypesUpdateOne { + if i != nil { + otuo.SetInt8(*i) + } + return otuo +} + // AddInt8 adds i to the "int8" field. func (otuo *OASTypesUpdateOne) AddInt8(i int8) *OASTypesUpdateOne { otuo.mutation.AddInt8(i) @@ -648,6 +816,14 @@ func (otuo *OASTypesUpdateOne) SetInt16(i int16) *OASTypesUpdateOne { return otuo } +// SetNillableInt16 sets the "int16" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableInt16(i *int16) *OASTypesUpdateOne { + if i != nil { + otuo.SetInt16(*i) + } + return otuo +} + // AddInt16 adds i to the "int16" field. func (otuo *OASTypesUpdateOne) AddInt16(i int16) *OASTypesUpdateOne { otuo.mutation.AddInt16(i) @@ -661,6 +837,14 @@ func (otuo *OASTypesUpdateOne) SetInt32(i int32) *OASTypesUpdateOne { return otuo } +// SetNillableInt32 sets the "int32" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableInt32(i *int32) *OASTypesUpdateOne { + if i != nil { + otuo.SetInt32(*i) + } + return otuo +} + // AddInt32 adds i to the "int32" field. func (otuo *OASTypesUpdateOne) AddInt32(i int32) *OASTypesUpdateOne { otuo.mutation.AddInt32(i) @@ -674,6 +858,14 @@ func (otuo *OASTypesUpdateOne) SetInt64(i int64) *OASTypesUpdateOne { return otuo } +// SetNillableInt64 sets the "int64" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableInt64(i *int64) *OASTypesUpdateOne { + if i != nil { + otuo.SetInt64(*i) + } + return otuo +} + // AddInt64 adds i to the "int64" field. func (otuo *OASTypesUpdateOne) AddInt64(i int64) *OASTypesUpdateOne { otuo.mutation.AddInt64(i) @@ -687,6 +879,14 @@ func (otuo *OASTypesUpdateOne) SetUint(u uint) *OASTypesUpdateOne { return otuo } +// SetNillableUint sets the "uint" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableUint(u *uint) *OASTypesUpdateOne { + if u != nil { + otuo.SetUint(*u) + } + return otuo +} + // AddUint adds u to the "uint" field. func (otuo *OASTypesUpdateOne) AddUint(u int) *OASTypesUpdateOne { otuo.mutation.AddUint(u) @@ -700,6 +900,14 @@ func (otuo *OASTypesUpdateOne) SetUint8(u uint8) *OASTypesUpdateOne { return otuo } +// SetNillableUint8 sets the "uint8" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableUint8(u *uint8) *OASTypesUpdateOne { + if u != nil { + otuo.SetUint8(*u) + } + return otuo +} + // AddUint8 adds u to the "uint8" field. func (otuo *OASTypesUpdateOne) AddUint8(u int8) *OASTypesUpdateOne { otuo.mutation.AddUint8(u) @@ -713,6 +921,14 @@ func (otuo *OASTypesUpdateOne) SetUint16(u uint16) *OASTypesUpdateOne { return otuo } +// SetNillableUint16 sets the "uint16" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableUint16(u *uint16) *OASTypesUpdateOne { + if u != nil { + otuo.SetUint16(*u) + } + return otuo +} + // AddUint16 adds u to the "uint16" field. func (otuo *OASTypesUpdateOne) AddUint16(u int16) *OASTypesUpdateOne { otuo.mutation.AddUint16(u) @@ -726,6 +942,14 @@ func (otuo *OASTypesUpdateOne) SetUint32(u uint32) *OASTypesUpdateOne { return otuo } +// SetNillableUint32 sets the "uint32" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableUint32(u *uint32) *OASTypesUpdateOne { + if u != nil { + otuo.SetUint32(*u) + } + return otuo +} + // AddUint32 adds u to the "uint32" field. func (otuo *OASTypesUpdateOne) AddUint32(u int32) *OASTypesUpdateOne { otuo.mutation.AddUint32(u) @@ -739,6 +963,14 @@ func (otuo *OASTypesUpdateOne) SetUint64(u uint64) *OASTypesUpdateOne { return otuo } +// SetNillableUint64 sets the "uint64" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableUint64(u *uint64) *OASTypesUpdateOne { + if u != nil { + otuo.SetUint64(*u) + } + return otuo +} + // AddUint64 adds u to the "uint64" field. func (otuo *OASTypesUpdateOne) AddUint64(u int64) *OASTypesUpdateOne { otuo.mutation.AddUint64(u) @@ -752,6 +984,14 @@ func (otuo *OASTypesUpdateOne) SetFloat32(f float32) *OASTypesUpdateOne { return otuo } +// SetNillableFloat32 sets the "float32" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableFloat32(f *float32) *OASTypesUpdateOne { + if f != nil { + otuo.SetFloat32(*f) + } + return otuo +} + // AddFloat32 adds f to the "float32" field. func (otuo *OASTypesUpdateOne) AddFloat32(f float32) *OASTypesUpdateOne { otuo.mutation.AddFloat32(f) @@ -765,6 +1005,14 @@ func (otuo *OASTypesUpdateOne) SetFloat64(f float64) *OASTypesUpdateOne { return otuo } +// SetNillableFloat64 sets the "float64" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableFloat64(f *float64) *OASTypesUpdateOne { + if f != nil { + otuo.SetFloat64(*f) + } + return otuo +} + // AddFloat64 adds f to the "float64" field. func (otuo *OASTypesUpdateOne) AddFloat64(f float64) *OASTypesUpdateOne { otuo.mutation.AddFloat64(f) @@ -777,12 +1025,28 @@ func (otuo *OASTypesUpdateOne) SetStringField(s string) *OASTypesUpdateOne { return otuo } +// SetNillableStringField sets the "string_field" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableStringField(s *string) *OASTypesUpdateOne { + if s != nil { + otuo.SetStringField(*s) + } + return otuo +} + // SetBool sets the "bool" field. func (otuo *OASTypesUpdateOne) SetBool(b bool) *OASTypesUpdateOne { otuo.mutation.SetBool(b) return otuo } +// SetNillableBool sets the "bool" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableBool(b *bool) *OASTypesUpdateOne { + if b != nil { + otuo.SetBool(*b) + } + return otuo +} + // SetUUID sets the "uuid" field. func (otuo *OASTypesUpdateOne) SetUUID(u uuid.UUID) *OASTypesUpdateOne { otuo.mutation.SetUUID(u) @@ -803,18 +1067,42 @@ func (otuo *OASTypesUpdateOne) SetTime(t time.Time) *OASTypesUpdateOne { return otuo } +// SetNillableTime sets the "time" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableTime(t *time.Time) *OASTypesUpdateOne { + if t != nil { + otuo.SetTime(*t) + } + return otuo +} + // SetText sets the "text" field. func (otuo *OASTypesUpdateOne) SetText(s string) *OASTypesUpdateOne { otuo.mutation.SetText(s) return otuo } +// SetNillableText sets the "text" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableText(s *string) *OASTypesUpdateOne { + if s != nil { + otuo.SetText(*s) + } + return otuo +} + // SetState sets the "state" field. func (otuo *OASTypesUpdateOne) SetState(o oastypes.State) *OASTypesUpdateOne { otuo.mutation.SetState(o) return otuo } +// SetNillableState sets the "state" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableState(o *oastypes.State) *OASTypesUpdateOne { + if o != nil { + otuo.SetState(*o) + } + return otuo +} + // SetStrings sets the "strings" field. func (otuo *OASTypesUpdateOne) SetStrings(s []string) *OASTypesUpdateOne { otuo.mutation.SetStrings(s) @@ -887,6 +1175,14 @@ func (otuo *OASTypesUpdateOne) SetJSONObj(u url.URL) *OASTypesUpdateOne { return otuo } +// SetNillableJSONObj sets the "json_obj" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableJSONObj(u *url.URL) *OASTypesUpdateOne { + if u != nil { + otuo.SetJSONObj(*u) + } + return otuo +} + // SetOther sets the "other" field. func (otuo *OASTypesUpdateOne) SetOther(s *schema.Link) *OASTypesUpdateOne { otuo.mutation.SetOther(s) @@ -927,6 +1223,14 @@ func (otuo *OASTypesUpdateOne) SetNillable(i int) *OASTypesUpdateOne { return otuo } +// SetNillableNillable sets the "nillable" field if the given value is not nil. +func (otuo *OASTypesUpdateOne) SetNillableNillable(i *int) *OASTypesUpdateOne { + if i != nil { + otuo.SetNillable(*i) + } + return otuo +} + // AddNillable adds i to the "nillable" field. func (otuo *OASTypesUpdateOne) AddNillable(i int) *OASTypesUpdateOne { otuo.mutation.AddNillable(i) @@ -980,7 +1284,7 @@ func (otuo *OASTypesUpdateOne) Select(field string, fields ...string) *OASTypesU // Save executes the query and returns the updated OASTypes entity. func (otuo *OASTypesUpdateOne) Save(ctx context.Context) (*OASTypes, error) { - return withHooks[*OASTypes, OASTypesMutation](ctx, otuo.sqlSave, otuo.mutation, otuo.hooks) + return withHooks(ctx, otuo.sqlSave, otuo.mutation, otuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entoas/internal/oastypes/runtime/runtime.go b/entoas/internal/oastypes/runtime/runtime.go index d3dd7ed5a..8e6522150 100644 --- a/entoas/internal/oastypes/runtime/runtime.go +++ b/entoas/internal/oastypes/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entoas/internal/oastypes/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entoas/internal/pets/category/where.go b/entoas/internal/pets/category/where.go index 5b88fa91c..013b99511 100644 --- a/entoas/internal/pets/category/where.go +++ b/entoas/internal/pets/category/where.go @@ -148,32 +148,15 @@ func HasPetsWith(preds ...predicate.Pet) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entoas/internal/pets/category_create.go b/entoas/internal/pets/category_create.go index c923411e8..b713f8053 100644 --- a/entoas/internal/pets/category_create.go +++ b/entoas/internal/pets/category_create.go @@ -48,7 +48,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -130,11 +130,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entoas/internal/pets/category_delete.go b/entoas/internal/pets/category_delete.go index 40b60e689..2f1899049 100644 --- a/entoas/internal/pets/category_delete.go +++ b/entoas/internal/pets/category_delete.go @@ -27,7 +27,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/pets/category_update.go b/entoas/internal/pets/category_update.go index dbcbfaf0f..9102aae89 100644 --- a/entoas/internal/pets/category_update.go +++ b/entoas/internal/pets/category_update.go @@ -34,6 +34,14 @@ func (cu *CategoryUpdate) SetName(s string) *CategoryUpdate { return cu } +// SetNillableName sets the "name" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableName(s *string) *CategoryUpdate { + if s != nil { + cu.SetName(*s) + } + return cu +} + // AddPetIDs adds the "pets" edge to the Pet entity by IDs. func (cu *CategoryUpdate) AddPetIDs(ids ...int) *CategoryUpdate { cu.mutation.AddPetIDs(ids...) @@ -77,7 +85,7 @@ func (cu *CategoryUpdate) RemovePets(p ...*Pet) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -185,6 +193,14 @@ func (cuo *CategoryUpdateOne) SetName(s string) *CategoryUpdateOne { return cuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableName(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetName(*s) + } + return cuo +} + // AddPetIDs adds the "pets" edge to the Pet entity by IDs. func (cuo *CategoryUpdateOne) AddPetIDs(ids ...int) *CategoryUpdateOne { cuo.mutation.AddPetIDs(ids...) @@ -241,7 +257,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entoas/internal/pets/client.go b/entoas/internal/pets/client.go index a8790f0b9..5c693d175 100644 --- a/entoas/internal/pets/client.go +++ b/entoas/internal/pets/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entoas/internal/pets/migrate" "entgo.io/ent" @@ -113,11 +114,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("pets: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("pets: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -241,6 +245,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -375,6 +394,21 @@ func (c *PetClient) CreateBulk(builders ...*PetCreate) *PetCreateBulk { return &PetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PetClient) MapCreateBulk(slice any, setFunc func(*PetCreate, int)) *PetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PetCreateBulk{err: fmt.Errorf("calling to PetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Pet. func (c *PetClient) Update() *PetUpdate { mutation := newPetMutation(c.config, OpUpdate) @@ -541,6 +575,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/entoas/internal/pets/pet/where.go b/entoas/internal/pets/pet/where.go index 9cfafce0e..882c52ed2 100644 --- a/entoas/internal/pets/pet/where.go +++ b/entoas/internal/pets/pet/where.go @@ -259,32 +259,15 @@ func HasFriendsWith(preds ...predicate.Pet) predicate.Pet { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Pet(sql.NotPredicates(p)) } diff --git a/entoas/internal/pets/pet_create.go b/entoas/internal/pets/pet_create.go index 410012c2c..3caee9c84 100644 --- a/entoas/internal/pets/pet_create.go +++ b/entoas/internal/pets/pet_create.go @@ -109,7 +109,7 @@ func (pc *PetCreate) Mutation() *PetMutation { // Save creates the Pet in the database. func (pc *PetCreate) Save(ctx context.Context) (*Pet, error) { - return withHooks[*Pet, PetMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -238,11 +238,15 @@ func (pc *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) { // PetCreateBulk is the builder for creating many Pet entities in bulk. type PetCreateBulk struct { config + err error builders []*PetCreate } // Save creates the Pet entities in the database. func (pcb *PetCreateBulk) Save(ctx context.Context) ([]*Pet, error) { + if pcb.err != nil { + return nil, pcb.err + } specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) nodes := make([]*Pet, len(pcb.builders)) mutators := make([]Mutator, len(pcb.builders)) diff --git a/entoas/internal/pets/pet_delete.go b/entoas/internal/pets/pet_delete.go index 936750f67..d03076b00 100644 --- a/entoas/internal/pets/pet_delete.go +++ b/entoas/internal/pets/pet_delete.go @@ -27,7 +27,7 @@ func (pd *PetDelete) Where(ps ...predicate.Pet) *PetDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *PetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/pets/pet_update.go b/entoas/internal/pets/pet_update.go index 75c0069c1..83836b93e 100644 --- a/entoas/internal/pets/pet_update.go +++ b/entoas/internal/pets/pet_update.go @@ -36,6 +36,14 @@ func (pu *PetUpdate) SetName(s string) *PetUpdate { return pu } +// SetNillableName sets the "name" field if the given value is not nil. +func (pu *PetUpdate) SetNillableName(s *string) *PetUpdate { + if s != nil { + pu.SetName(*s) + } + return pu +} + // SetNicknames sets the "nicknames" field. func (pu *PetUpdate) SetNicknames(s []string) *PetUpdate { pu.mutation.SetNicknames(s) @@ -185,7 +193,7 @@ func (pu *PetUpdate) RemoveFriends(p ...*Pet) *PetUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -387,6 +395,14 @@ func (puo *PetUpdateOne) SetName(s string) *PetUpdateOne { return puo } +// SetNillableName sets the "name" field if the given value is not nil. +func (puo *PetUpdateOne) SetNillableName(s *string) *PetUpdateOne { + if s != nil { + puo.SetName(*s) + } + return puo +} + // SetNicknames sets the "nicknames" field. func (puo *PetUpdateOne) SetNicknames(s []string) *PetUpdateOne { puo.mutation.SetNicknames(s) @@ -549,7 +565,7 @@ func (puo *PetUpdateOne) Select(field string, fields ...string) *PetUpdateOne { // Save executes the query and returns the updated Pet entity. func (puo *PetUpdateOne) Save(ctx context.Context) (*Pet, error) { - return withHooks[*Pet, PetMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entoas/internal/pets/runtime/runtime.go b/entoas/internal/pets/runtime/runtime.go index c05ba1a49..34bb46359 100644 --- a/entoas/internal/pets/runtime/runtime.go +++ b/entoas/internal/pets/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entoas/internal/pets/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entoas/internal/pets/user/where.go b/entoas/internal/pets/user/where.go index 88e7f8f5b..fa64e577d 100644 --- a/entoas/internal/pets/user/where.go +++ b/entoas/internal/pets/user/where.go @@ -193,32 +193,15 @@ func HasPetsWith(preds ...predicate.Pet) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entoas/internal/pets/user_create.go b/entoas/internal/pets/user_create.go index 943e7a9d0..494d07dbf 100644 --- a/entoas/internal/pets/user_create.go +++ b/entoas/internal/pets/user_create.go @@ -54,7 +54,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -143,11 +143,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entoas/internal/pets/user_delete.go b/entoas/internal/pets/user_delete.go index 83ac793c6..6bd875e8e 100644 --- a/entoas/internal/pets/user_delete.go +++ b/entoas/internal/pets/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/pets/user_update.go b/entoas/internal/pets/user_update.go index da0b1adc7..14c733fd3 100644 --- a/entoas/internal/pets/user_update.go +++ b/entoas/internal/pets/user_update.go @@ -34,6 +34,14 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate { return uu } +// SetNillableName sets the "name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { + if s != nil { + uu.SetName(*s) + } + return uu +} + // SetAge sets the "age" field. func (uu *UserUpdate) SetAge(i int) *UserUpdate { uu.mutation.ResetAge() @@ -41,6 +49,14 @@ func (uu *UserUpdate) SetAge(i int) *UserUpdate { return uu } +// SetNillableAge sets the "age" field if the given value is not nil. +func (uu *UserUpdate) SetNillableAge(i *int) *UserUpdate { + if i != nil { + uu.SetAge(*i) + } + return uu +} + // AddAge adds i to the "age" field. func (uu *UserUpdate) AddAge(i int) *UserUpdate { uu.mutation.AddAge(i) @@ -90,7 +106,7 @@ func (uu *UserUpdate) RemovePets(p ...*Pet) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -204,6 +220,14 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { return uuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetName(*s) + } + return uuo +} + // SetAge sets the "age" field. func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne { uuo.mutation.ResetAge() @@ -211,6 +235,14 @@ func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne { return uuo } +// SetNillableAge sets the "age" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableAge(i *int) *UserUpdateOne { + if i != nil { + uuo.SetAge(*i) + } + return uuo +} + // AddAge adds i to the "age" field. func (uuo *UserUpdateOne) AddAge(i int) *UserUpdateOne { uuo.mutation.AddAge(i) @@ -273,7 +305,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entoas/internal/simple/category/where.go b/entoas/internal/simple/category/where.go index ee67748fb..8b4b8a191 100644 --- a/entoas/internal/simple/category/where.go +++ b/entoas/internal/simple/category/where.go @@ -288,32 +288,15 @@ func HasPetsWith(preds ...predicate.Pet) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entoas/internal/simple/category_create.go b/entoas/internal/simple/category_create.go index a9153e787..d42201344 100644 --- a/entoas/internal/simple/category_create.go +++ b/entoas/internal/simple/category_create.go @@ -60,7 +60,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -156,11 +156,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entoas/internal/simple/category_delete.go b/entoas/internal/simple/category_delete.go index b4a612787..b277d470e 100644 --- a/entoas/internal/simple/category_delete.go +++ b/entoas/internal/simple/category_delete.go @@ -27,7 +27,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/simple/category_update.go b/entoas/internal/simple/category_update.go index a281f7a4b..ed28fd92a 100644 --- a/entoas/internal/simple/category_update.go +++ b/entoas/internal/simple/category_update.go @@ -34,18 +34,42 @@ func (cu *CategoryUpdate) SetName(s string) *CategoryUpdate { return cu } +// SetNillableName sets the "name" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableName(s *string) *CategoryUpdate { + if s != nil { + cu.SetName(*s) + } + return cu +} + // SetReadonly sets the "readonly" field. func (cu *CategoryUpdate) SetReadonly(s string) *CategoryUpdate { cu.mutation.SetReadonly(s) return cu } +// SetNillableReadonly sets the "readonly" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableReadonly(s *string) *CategoryUpdate { + if s != nil { + cu.SetReadonly(*s) + } + return cu +} + // SetSkipInSpec sets the "skip_in_spec" field. func (cu *CategoryUpdate) SetSkipInSpec(s string) *CategoryUpdate { cu.mutation.SetSkipInSpec(s) return cu } +// SetNillableSkipInSpec sets the "skip_in_spec" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableSkipInSpec(s *string) *CategoryUpdate { + if s != nil { + cu.SetSkipInSpec(*s) + } + return cu +} + // AddPetIDs adds the "pets" edge to the Pet entity by IDs. func (cu *CategoryUpdate) AddPetIDs(ids ...int) *CategoryUpdate { cu.mutation.AddPetIDs(ids...) @@ -89,7 +113,7 @@ func (cu *CategoryUpdate) RemovePets(p ...*Pet) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -203,18 +227,42 @@ func (cuo *CategoryUpdateOne) SetName(s string) *CategoryUpdateOne { return cuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableName(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetName(*s) + } + return cuo +} + // SetReadonly sets the "readonly" field. func (cuo *CategoryUpdateOne) SetReadonly(s string) *CategoryUpdateOne { cuo.mutation.SetReadonly(s) return cuo } +// SetNillableReadonly sets the "readonly" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableReadonly(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetReadonly(*s) + } + return cuo +} + // SetSkipInSpec sets the "skip_in_spec" field. func (cuo *CategoryUpdateOne) SetSkipInSpec(s string) *CategoryUpdateOne { cuo.mutation.SetSkipInSpec(s) return cuo } +// SetNillableSkipInSpec sets the "skip_in_spec" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableSkipInSpec(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetSkipInSpec(*s) + } + return cuo +} + // AddPetIDs adds the "pets" edge to the Pet entity by IDs. func (cuo *CategoryUpdateOne) AddPetIDs(ids ...int) *CategoryUpdateOne { cuo.mutation.AddPetIDs(ids...) @@ -271,7 +319,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entoas/internal/simple/client.go b/entoas/internal/simple/client.go index 2aab140e1..7d16e9a3e 100644 --- a/entoas/internal/simple/client.go +++ b/entoas/internal/simple/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entoas/internal/simple/migrate" "entgo.io/ent" @@ -113,11 +114,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("simple: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("simple: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -241,6 +245,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -375,6 +394,21 @@ func (c *PetClient) CreateBulk(builders ...*PetCreate) *PetCreateBulk { return &PetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PetClient) MapCreateBulk(slice any, setFunc func(*PetCreate, int)) *PetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PetCreateBulk{err: fmt.Errorf("calling to PetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Pet. func (c *PetClient) Update() *PetUpdate { mutation := newPetMutation(c.config, OpUpdate) @@ -541,6 +575,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/entoas/internal/simple/pet/where.go b/entoas/internal/simple/pet/where.go index 95aecff15..3db68bf95 100644 --- a/entoas/internal/simple/pet/where.go +++ b/entoas/internal/simple/pet/where.go @@ -259,32 +259,15 @@ func HasFriendsWith(preds ...predicate.Pet) predicate.Pet { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Pet(sql.NotPredicates(p)) } diff --git a/entoas/internal/simple/pet_create.go b/entoas/internal/simple/pet_create.go index e6d540fa6..8053823ff 100644 --- a/entoas/internal/simple/pet_create.go +++ b/entoas/internal/simple/pet_create.go @@ -109,7 +109,7 @@ func (pc *PetCreate) Mutation() *PetMutation { // Save creates the Pet in the database. func (pc *PetCreate) Save(ctx context.Context) (*Pet, error) { - return withHooks[*Pet, PetMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -238,11 +238,15 @@ func (pc *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) { // PetCreateBulk is the builder for creating many Pet entities in bulk. type PetCreateBulk struct { config + err error builders []*PetCreate } // Save creates the Pet entities in the database. func (pcb *PetCreateBulk) Save(ctx context.Context) ([]*Pet, error) { + if pcb.err != nil { + return nil, pcb.err + } specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) nodes := make([]*Pet, len(pcb.builders)) mutators := make([]Mutator, len(pcb.builders)) diff --git a/entoas/internal/simple/pet_delete.go b/entoas/internal/simple/pet_delete.go index 8d10408e6..9988fb8f0 100644 --- a/entoas/internal/simple/pet_delete.go +++ b/entoas/internal/simple/pet_delete.go @@ -27,7 +27,7 @@ func (pd *PetDelete) Where(ps ...predicate.Pet) *PetDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *PetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/simple/pet_update.go b/entoas/internal/simple/pet_update.go index 602ded5be..4129d65d8 100644 --- a/entoas/internal/simple/pet_update.go +++ b/entoas/internal/simple/pet_update.go @@ -36,6 +36,14 @@ func (pu *PetUpdate) SetName(s string) *PetUpdate { return pu } +// SetNillableName sets the "name" field if the given value is not nil. +func (pu *PetUpdate) SetNillableName(s *string) *PetUpdate { + if s != nil { + pu.SetName(*s) + } + return pu +} + // SetNicknames sets the "nicknames" field. func (pu *PetUpdate) SetNicknames(s []string) *PetUpdate { pu.mutation.SetNicknames(s) @@ -185,7 +193,7 @@ func (pu *PetUpdate) RemoveFriends(p ...*Pet) *PetUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -387,6 +395,14 @@ func (puo *PetUpdateOne) SetName(s string) *PetUpdateOne { return puo } +// SetNillableName sets the "name" field if the given value is not nil. +func (puo *PetUpdateOne) SetNillableName(s *string) *PetUpdateOne { + if s != nil { + puo.SetName(*s) + } + return puo +} + // SetNicknames sets the "nicknames" field. func (puo *PetUpdateOne) SetNicknames(s []string) *PetUpdateOne { puo.mutation.SetNicknames(s) @@ -549,7 +565,7 @@ func (puo *PetUpdateOne) Select(field string, fields ...string) *PetUpdateOne { // Save executes the query and returns the updated Pet entity. func (puo *PetUpdateOne) Save(ctx context.Context) (*Pet, error) { - return withHooks[*Pet, PetMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entoas/internal/simple/runtime/runtime.go b/entoas/internal/simple/runtime/runtime.go index c35d52eee..48d982bcf 100644 --- a/entoas/internal/simple/runtime/runtime.go +++ b/entoas/internal/simple/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entoas/internal/simple/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entoas/internal/simple/user/where.go b/entoas/internal/simple/user/where.go index bf14ee44e..0adf2307e 100644 --- a/entoas/internal/simple/user/where.go +++ b/entoas/internal/simple/user/where.go @@ -193,32 +193,15 @@ func HasPetsWith(preds ...predicate.Pet) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entoas/internal/simple/user_create.go b/entoas/internal/simple/user_create.go index 28777712d..566f956fd 100644 --- a/entoas/internal/simple/user_create.go +++ b/entoas/internal/simple/user_create.go @@ -54,7 +54,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -143,11 +143,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entoas/internal/simple/user_delete.go b/entoas/internal/simple/user_delete.go index 80840662d..9261b861c 100644 --- a/entoas/internal/simple/user_delete.go +++ b/entoas/internal/simple/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entoas/internal/simple/user_update.go b/entoas/internal/simple/user_update.go index b3f00dd77..a7455b817 100644 --- a/entoas/internal/simple/user_update.go +++ b/entoas/internal/simple/user_update.go @@ -34,6 +34,14 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate { return uu } +// SetNillableName sets the "name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { + if s != nil { + uu.SetName(*s) + } + return uu +} + // SetAge sets the "age" field. func (uu *UserUpdate) SetAge(i int) *UserUpdate { uu.mutation.ResetAge() @@ -41,6 +49,14 @@ func (uu *UserUpdate) SetAge(i int) *UserUpdate { return uu } +// SetNillableAge sets the "age" field if the given value is not nil. +func (uu *UserUpdate) SetNillableAge(i *int) *UserUpdate { + if i != nil { + uu.SetAge(*i) + } + return uu +} + // AddAge adds i to the "age" field. func (uu *UserUpdate) AddAge(i int) *UserUpdate { uu.mutation.AddAge(i) @@ -90,7 +106,7 @@ func (uu *UserUpdate) RemovePets(p ...*Pet) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -204,6 +220,14 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { return uuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetName(*s) + } + return uuo +} + // SetAge sets the "age" field. func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne { uuo.mutation.ResetAge() @@ -211,6 +235,14 @@ func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne { return uuo } +// SetNillableAge sets the "age" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableAge(i *int) *UserUpdateOne { + if i != nil { + uuo.SetAge(*i) + } + return uuo +} + // AddAge adds i to the "age" field. func (uuo *UserUpdateOne) AddAge(i int) *UserUpdateOne { uuo.mutation.AddAge(i) @@ -273,7 +305,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/Dockerfile b/entproto/Dockerfile index 8042a1fa7..d9e1cb89b 100644 --- a/entproto/Dockerfile +++ b/entproto/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.0 +FROM golang:1.21.0 RUN apt update && apt install unzip RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip && \ unzip -o protoc-3.19.4-linux-x86_64.zip -d ./proto && \ diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment/where.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment/where.go index e63d083d0..a39f6c93f 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment/where.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment/where.go @@ -134,32 +134,15 @@ func ContentsContainsFold(v string) predicate.Attachment { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Attachment) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Attachment(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Attachment) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Attachment(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Attachment) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Attachment(sql.NotPredicates(p)) } diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_create.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_create.go index 8ae46a6cb..9abdd2def 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_create.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_create.go @@ -38,7 +38,7 @@ func (ac *AttachmentCreate) Mutation() *AttachmentMutation { // Save creates the Attachment in the database. func (ac *AttachmentCreate) Save(ctx context.Context) (*Attachment, error) { - return withHooks[*Attachment, AttachmentMutation](ctx, ac.sqlSave, ac.mutation, ac.hooks) + return withHooks(ctx, ac.sqlSave, ac.mutation, ac.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -113,11 +113,15 @@ func (ac *AttachmentCreate) createSpec() (*Attachment, *sqlgraph.CreateSpec) { // AttachmentCreateBulk is the builder for creating many Attachment entities in bulk. type AttachmentCreateBulk struct { config + err error builders []*AttachmentCreate } // Save creates the Attachment entities in the database. func (acb *AttachmentCreateBulk) Save(ctx context.Context) ([]*Attachment, error) { + if acb.err != nil { + return nil, acb.err + } specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) nodes := make([]*Attachment, len(acb.builders)) mutators := make([]Mutator, len(acb.builders)) diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_delete.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_delete.go index 449c8cf64..829b0ef5a 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_delete.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_delete.go @@ -27,7 +27,7 @@ func (ad *AttachmentDelete) Where(ps ...predicate.Attachment) *AttachmentDelete // Exec executes the deletion query and returns how many vertices were deleted. func (ad *AttachmentDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, AttachmentMutation](ctx, ad.sqlExec, ad.mutation, ad.hooks) + return withHooks(ctx, ad.sqlExec, ad.mutation, ad.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_update.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_update.go index 89e095c55..bafd472fa 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_update.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/attachment_update.go @@ -33,6 +33,14 @@ func (au *AttachmentUpdate) SetContents(s string) *AttachmentUpdate { return au } +// SetNillableContents sets the "contents" field if the given value is not nil. +func (au *AttachmentUpdate) SetNillableContents(s *string) *AttachmentUpdate { + if s != nil { + au.SetContents(*s) + } + return au +} + // Mutation returns the AttachmentMutation object of the builder. func (au *AttachmentUpdate) Mutation() *AttachmentMutation { return au.mutation @@ -40,7 +48,7 @@ func (au *AttachmentUpdate) Mutation() *AttachmentMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (au *AttachmentUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, AttachmentMutation](ctx, au.sqlSave, au.mutation, au.hooks) + return withHooks(ctx, au.sqlSave, au.mutation, au.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -103,6 +111,14 @@ func (auo *AttachmentUpdateOne) SetContents(s string) *AttachmentUpdateOne { return auo } +// SetNillableContents sets the "contents" field if the given value is not nil. +func (auo *AttachmentUpdateOne) SetNillableContents(s *string) *AttachmentUpdateOne { + if s != nil { + auo.SetContents(*s) + } + return auo +} + // Mutation returns the AttachmentMutation object of the builder. func (auo *AttachmentUpdateOne) Mutation() *AttachmentMutation { return auo.mutation @@ -123,7 +139,7 @@ func (auo *AttachmentUpdateOne) Select(field string, fields ...string) *Attachme // Save executes the query and returns the updated Attachment entity. func (auo *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) { - return withHooks[*Attachment, AttachmentMutation](ctx, auo.sqlSave, auo.mutation, auo.hooks) + return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/client.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/client.go index 6633654f3..776d6526e 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/client.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entproto/cmd/protoc-gen-ent/internal/todo/ent/migrate" "entgo.io/ent" @@ -116,11 +117,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -250,6 +254,21 @@ func (c *AttachmentClient) CreateBulk(builders ...*AttachmentCreate) *Attachment return &AttachmentCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *AttachmentClient) MapCreateBulk(slice any, setFunc func(*AttachmentCreate, int)) *AttachmentCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AttachmentCreateBulk{err: fmt.Errorf("calling to AttachmentClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AttachmentCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AttachmentCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Attachment. func (c *AttachmentClient) Update() *AttachmentUpdate { mutation := newAttachmentMutation(c.config, OpUpdate) @@ -368,6 +387,21 @@ func (c *FileClient) CreateBulk(builders ...*FileCreate) *FileCreateBulk { return &FileCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *FileClient) MapCreateBulk(slice any, setFunc func(*FileCreate, int)) *FileCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &FileCreateBulk{err: fmt.Errorf("calling to FileClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*FileCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &FileCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for File. func (c *FileClient) Update() *FileUpdate { mutation := newFileMutation(c.config, OpUpdate) @@ -486,6 +520,21 @@ func (c *TaskClient) CreateBulk(builders ...*TaskCreate) *TaskCreateBulk { return &TaskCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TaskClient) MapCreateBulk(slice any, setFunc func(*TaskCreate, int)) *TaskCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TaskCreateBulk{err: fmt.Errorf("calling to TaskClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TaskCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TaskCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Task. func (c *TaskClient) Update() *TaskUpdate { mutation := newTaskMutation(c.config, OpUpdate) @@ -604,6 +653,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file/where.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file/where.go index 92c47c9af..51f67ce7f 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file/where.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file/where.go @@ -134,32 +134,15 @@ func ContentsContainsFold(v string) predicate.File { // And groups predicates with the AND operator between them. func And(predicates ...predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.File(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.File(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.File(sql.NotPredicates(p)) } diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_create.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_create.go index 466a6c71a..0814f52bd 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_create.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_create.go @@ -38,7 +38,7 @@ func (fc *FileCreate) Mutation() *FileMutation { // Save creates the File in the database. func (fc *FileCreate) Save(ctx context.Context) (*File, error) { - return withHooks[*File, FileMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) + return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -113,11 +113,15 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { // FileCreateBulk is the builder for creating many File entities in bulk. type FileCreateBulk struct { config + err error builders []*FileCreate } // Save creates the File entities in the database. func (fcb *FileCreateBulk) Save(ctx context.Context) ([]*File, error) { + if fcb.err != nil { + return nil, fcb.err + } specs := make([]*sqlgraph.CreateSpec, len(fcb.builders)) nodes := make([]*File, len(fcb.builders)) mutators := make([]Mutator, len(fcb.builders)) diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_delete.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_delete.go index c096e5417..d9f466011 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_delete.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_delete.go @@ -27,7 +27,7 @@ func (fd *FileDelete) Where(ps ...predicate.File) *FileDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FileDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, FileMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) + return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_update.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_update.go index 0578f8e72..5008d7e8d 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_update.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/file_update.go @@ -33,6 +33,14 @@ func (fu *FileUpdate) SetContents(s string) *FileUpdate { return fu } +// SetNillableContents sets the "contents" field if the given value is not nil. +func (fu *FileUpdate) SetNillableContents(s *string) *FileUpdate { + if s != nil { + fu.SetContents(*s) + } + return fu +} + // Mutation returns the FileMutation object of the builder. func (fu *FileUpdate) Mutation() *FileMutation { return fu.mutation @@ -40,7 +48,7 @@ func (fu *FileUpdate) Mutation() *FileMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FileUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, FileMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) + return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -103,6 +111,14 @@ func (fuo *FileUpdateOne) SetContents(s string) *FileUpdateOne { return fuo } +// SetNillableContents sets the "contents" field if the given value is not nil. +func (fuo *FileUpdateOne) SetNillableContents(s *string) *FileUpdateOne { + if s != nil { + fuo.SetContents(*s) + } + return fuo +} + // Mutation returns the FileMutation object of the builder. func (fuo *FileUpdateOne) Mutation() *FileMutation { return fuo.mutation @@ -123,7 +139,7 @@ func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne // Save executes the query and returns the updated File entity. func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) { - return withHooks[*File, FileMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) + return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/runtime/runtime.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/runtime/runtime.go index 7d9abdad6..5a422cf01 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/runtime/runtime.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entproto/cmd/protoc-gen-ent/internal/todo/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task/where.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task/where.go index 976c10083..299f87267 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task/where.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task/where.go @@ -289,32 +289,15 @@ func SignatureContainsFold(v string) predicate.Task { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Task) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Task(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Task) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Task(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Task) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Task(sql.NotPredicates(p)) } diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_create.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_create.go index 865566ad1..370a917cf 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_create.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_create.go @@ -58,7 +58,7 @@ func (tc *TaskCreate) Mutation() *TaskMutation { // Save creates the Task in the database. func (tc *TaskCreate) Save(ctx context.Context) (*Task, error) { - return withHooks[*Task, TaskMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -142,11 +142,15 @@ func (tc *TaskCreate) createSpec() (*Task, *sqlgraph.CreateSpec) { // TaskCreateBulk is the builder for creating many Task entities in bulk. type TaskCreateBulk struct { config + err error builders []*TaskCreate } // Save creates the Task entities in the database. func (tcb *TaskCreateBulk) Save(ctx context.Context) ([]*Task, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Task, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_delete.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_delete.go index 2429ad7c1..ad5234ba6 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_delete.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_delete.go @@ -27,7 +27,7 @@ func (td *TaskDelete) Where(ps ...predicate.Task) *TaskDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TaskDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TaskMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_update.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_update.go index 8e1c03f0b..54a95390c 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_update.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/task_update.go @@ -53,12 +53,28 @@ func (tu *TaskUpdate) SetComplete(b bool) *TaskUpdate { return tu } +// SetNillableComplete sets the "complete" field if the given value is not nil. +func (tu *TaskUpdate) SetNillableComplete(b *bool) *TaskUpdate { + if b != nil { + tu.SetComplete(*b) + } + return tu +} + // SetSignature sets the "signature" field. func (tu *TaskUpdate) SetSignature(s string) *TaskUpdate { tu.mutation.SetSignature(s) return tu } +// SetNillableSignature sets the "signature" field if the given value is not nil. +func (tu *TaskUpdate) SetNillableSignature(s *string) *TaskUpdate { + if s != nil { + tu.SetSignature(*s) + } + return tu +} + // Mutation returns the TaskMutation object of the builder. func (tu *TaskUpdate) Mutation() *TaskMutation { return tu.mutation @@ -66,7 +82,7 @@ func (tu *TaskUpdate) Mutation() *TaskMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TaskUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TaskMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -158,12 +174,28 @@ func (tuo *TaskUpdateOne) SetComplete(b bool) *TaskUpdateOne { return tuo } +// SetNillableComplete sets the "complete" field if the given value is not nil. +func (tuo *TaskUpdateOne) SetNillableComplete(b *bool) *TaskUpdateOne { + if b != nil { + tuo.SetComplete(*b) + } + return tuo +} + // SetSignature sets the "signature" field. func (tuo *TaskUpdateOne) SetSignature(s string) *TaskUpdateOne { tuo.mutation.SetSignature(s) return tuo } +// SetNillableSignature sets the "signature" field if the given value is not nil. +func (tuo *TaskUpdateOne) SetNillableSignature(s *string) *TaskUpdateOne { + if s != nil { + tuo.SetSignature(*s) + } + return tuo +} + // Mutation returns the TaskMutation object of the builder. func (tuo *TaskUpdateOne) Mutation() *TaskMutation { return tuo.mutation @@ -184,7 +216,7 @@ func (tuo *TaskUpdateOne) Select(field string, fields ...string) *TaskUpdateOne // Save executes the query and returns the updated Task entity. func (tuo *TaskUpdateOne) Save(ctx context.Context) (*Task, error) { - return withHooks[*Task, TaskMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user/where.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user/where.go index 79c82154b..eb926275d 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user/where.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user/where.go @@ -124,32 +124,15 @@ func NameContainsFold(v string) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_create.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_create.go index a84b3e081..94c779fd9 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_create.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_create.go @@ -32,7 +32,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -98,11 +98,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_delete.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_delete.go index 698f9cef7..3eca051e3 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_delete.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_update.go b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_update.go index 89154a909..012d453e9 100644 --- a/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_update.go +++ b/entproto/cmd/protoc-gen-ent/internal/todo/ent/user_update.go @@ -33,6 +33,14 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate { return uu } +// SetNillableName sets the "name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { + if s != nil { + uu.SetName(*s) + } + return uu +} + // Mutation returns the UserMutation object of the builder. func (uu *UserUpdate) Mutation() *UserMutation { return uu.mutation @@ -40,7 +48,7 @@ func (uu *UserUpdate) Mutation() *UserMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -103,6 +111,14 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { return uuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetName(*s) + } + return uuo +} + // Mutation returns the UserMutation object of the builder. func (uuo *UserUpdateOne) Mutation() *UserMutation { return uuo.mutation @@ -123,7 +139,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/altdir/ent/client.go b/entproto/internal/altdir/ent/client.go index 34b06fdef..984a65b19 100644 --- a/entproto/internal/altdir/ent/client.go +++ b/entproto/internal/altdir/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entproto/internal/altdir/ent/migrate" "entgo.io/ent" @@ -104,11 +105,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -220,6 +224,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/entproto/internal/altdir/ent/runtime/runtime.go b/entproto/internal/altdir/ent/runtime/runtime.go index f615b5e44..f8dcf61e5 100644 --- a/entproto/internal/altdir/ent/runtime/runtime.go +++ b/entproto/internal/altdir/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entproto/internal/altdir/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entproto/internal/altdir/ent/user/where.go b/entproto/internal/altdir/ent/user/where.go index 494b8165c..c3e1cb08c 100644 --- a/entproto/internal/altdir/ent/user/where.go +++ b/entproto/internal/altdir/ent/user/where.go @@ -124,32 +124,15 @@ func NameContainsFold(v string) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entproto/internal/altdir/ent/user_create.go b/entproto/internal/altdir/ent/user_create.go index 587a219c1..a208a6d1d 100644 --- a/entproto/internal/altdir/ent/user_create.go +++ b/entproto/internal/altdir/ent/user_create.go @@ -32,7 +32,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -98,11 +98,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entproto/internal/altdir/ent/user_delete.go b/entproto/internal/altdir/ent/user_delete.go index b1fcac1ea..848a5d9e6 100644 --- a/entproto/internal/altdir/ent/user_delete.go +++ b/entproto/internal/altdir/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/altdir/ent/user_update.go b/entproto/internal/altdir/ent/user_update.go index 66e12b926..4d5849a75 100644 --- a/entproto/internal/altdir/ent/user_update.go +++ b/entproto/internal/altdir/ent/user_update.go @@ -33,6 +33,14 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate { return uu } +// SetNillableName sets the "name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { + if s != nil { + uu.SetName(*s) + } + return uu +} + // Mutation returns the UserMutation object of the builder. func (uu *UserUpdate) Mutation() *UserMutation { return uu.mutation @@ -40,7 +48,7 @@ func (uu *UserUpdate) Mutation() *UserMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -103,6 +111,14 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { return uuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetName(*s) + } + return uuo +} + // Mutation returns the UserMutation object of the builder. func (uuo *UserUpdateOne) Mutation() *UserMutation { return uuo.mutation @@ -123,7 +139,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/bare/ent/client.go b/entproto/internal/bare/ent/client.go index 91d1fdfc9..c478d045c 100644 --- a/entproto/internal/bare/ent/client.go +++ b/entproto/internal/bare/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entproto/internal/bare/ent/migrate" "entgo.io/ent" @@ -104,11 +105,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -220,6 +224,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/entproto/internal/bare/ent/runtime/runtime.go b/entproto/internal/bare/ent/runtime/runtime.go index 54af3be7c..eabb212f4 100644 --- a/entproto/internal/bare/ent/runtime/runtime.go +++ b/entproto/internal/bare/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entproto/internal/bare/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entproto/internal/bare/ent/user/where.go b/entproto/internal/bare/ent/user/where.go index f8afd4847..7ad3895bd 100644 --- a/entproto/internal/bare/ent/user/where.go +++ b/entproto/internal/bare/ent/user/where.go @@ -194,32 +194,15 @@ func EmailAddressContainsFold(v string) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entproto/internal/bare/ent/user_create.go b/entproto/internal/bare/ent/user_create.go index 52b726db4..faa9ca5ec 100644 --- a/entproto/internal/bare/ent/user_create.go +++ b/entproto/internal/bare/ent/user_create.go @@ -38,7 +38,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -111,11 +111,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entproto/internal/bare/ent/user_delete.go b/entproto/internal/bare/ent/user_delete.go index ff7f31ef8..6e580c429 100644 --- a/entproto/internal/bare/ent/user_delete.go +++ b/entproto/internal/bare/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/bare/ent/user_update.go b/entproto/internal/bare/ent/user_update.go index 1c9e5734c..a9b1f9403 100644 --- a/entproto/internal/bare/ent/user_update.go +++ b/entproto/internal/bare/ent/user_update.go @@ -33,12 +33,28 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate { return uu } +// SetNillableName sets the "name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { + if s != nil { + uu.SetName(*s) + } + return uu +} + // SetEmailAddress sets the "email_address" field. func (uu *UserUpdate) SetEmailAddress(s string) *UserUpdate { uu.mutation.SetEmailAddress(s) return uu } +// SetNillableEmailAddress sets the "email_address" field if the given value is not nil. +func (uu *UserUpdate) SetNillableEmailAddress(s *string) *UserUpdate { + if s != nil { + uu.SetEmailAddress(*s) + } + return uu +} + // Mutation returns the UserMutation object of the builder. func (uu *UserUpdate) Mutation() *UserMutation { return uu.mutation @@ -46,7 +62,7 @@ func (uu *UserUpdate) Mutation() *UserMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -112,12 +128,28 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { return uuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetName(*s) + } + return uuo +} + // SetEmailAddress sets the "email_address" field. func (uuo *UserUpdateOne) SetEmailAddress(s string) *UserUpdateOne { uuo.mutation.SetEmailAddress(s) return uuo } +// SetNillableEmailAddress sets the "email_address" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableEmailAddress(s *string) *UserUpdateOne { + if s != nil { + uuo.SetEmailAddress(*s) + } + return uuo +} + // Mutation returns the UserMutation object of the builder. func (uuo *UserUpdateOne) Mutation() *UserMutation { return uuo.mutation @@ -138,7 +170,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/allmethodsservice/where.go b/entproto/internal/entprototest/ent/allmethodsservice/where.go index 8b8a3bb4e..2bf627e72 100644 --- a/entproto/internal/entprototest/ent/allmethodsservice/where.go +++ b/entproto/internal/entprototest/ent/allmethodsservice/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.AllMethodsService { // And groups predicates with the AND operator between them. func And(predicates ...predicate.AllMethodsService) predicate.AllMethodsService { - return predicate.AllMethodsService(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.AllMethodsService(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.AllMethodsService) predicate.AllMethodsService { - return predicate.AllMethodsService(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.AllMethodsService(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.AllMethodsService) predicate.AllMethodsService { - return predicate.AllMethodsService(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.AllMethodsService(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/allmethodsservice_create.go b/entproto/internal/entprototest/ent/allmethodsservice_create.go index bdb3e8924..81ad28020 100644 --- a/entproto/internal/entprototest/ent/allmethodsservice_create.go +++ b/entproto/internal/entprototest/ent/allmethodsservice_create.go @@ -25,7 +25,7 @@ func (amsc *AllMethodsServiceCreate) Mutation() *AllMethodsServiceMutation { // Save creates the AllMethodsService in the database. func (amsc *AllMethodsServiceCreate) Save(ctx context.Context) (*AllMethodsService, error) { - return withHooks[*AllMethodsService, AllMethodsServiceMutation](ctx, amsc.sqlSave, amsc.mutation, amsc.hooks) + return withHooks(ctx, amsc.sqlSave, amsc.mutation, amsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (amsc *AllMethodsServiceCreate) createSpec() (*AllMethodsService, *sqlgraph // AllMethodsServiceCreateBulk is the builder for creating many AllMethodsService entities in bulk. type AllMethodsServiceCreateBulk struct { config + err error builders []*AllMethodsServiceCreate } // Save creates the AllMethodsService entities in the database. func (amscb *AllMethodsServiceCreateBulk) Save(ctx context.Context) ([]*AllMethodsService, error) { + if amscb.err != nil { + return nil, amscb.err + } specs := make([]*sqlgraph.CreateSpec, len(amscb.builders)) nodes := make([]*AllMethodsService, len(amscb.builders)) mutators := make([]Mutator, len(amscb.builders)) diff --git a/entproto/internal/entprototest/ent/allmethodsservice_delete.go b/entproto/internal/entprototest/ent/allmethodsservice_delete.go index bbb70520b..30ec3ae8b 100644 --- a/entproto/internal/entprototest/ent/allmethodsservice_delete.go +++ b/entproto/internal/entprototest/ent/allmethodsservice_delete.go @@ -27,7 +27,7 @@ func (amsd *AllMethodsServiceDelete) Where(ps ...predicate.AllMethodsService) *A // Exec executes the deletion query and returns how many vertices were deleted. func (amsd *AllMethodsServiceDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, AllMethodsServiceMutation](ctx, amsd.sqlExec, amsd.mutation, amsd.hooks) + return withHooks(ctx, amsd.sqlExec, amsd.mutation, amsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/allmethodsservice_update.go b/entproto/internal/entprototest/ent/allmethodsservice_update.go index 7ae621f2e..72340e181 100644 --- a/entproto/internal/entprototest/ent/allmethodsservice_update.go +++ b/entproto/internal/entprototest/ent/allmethodsservice_update.go @@ -34,7 +34,7 @@ func (amsu *AllMethodsServiceUpdate) Mutation() *AllMethodsServiceMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (amsu *AllMethodsServiceUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, AllMethodsServiceMutation](ctx, amsu.sqlSave, amsu.mutation, amsu.hooks) + return withHooks(ctx, amsu.sqlSave, amsu.mutation, amsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (amsuo *AllMethodsServiceUpdateOne) Select(field string, fields ...string) // Save executes the query and returns the updated AllMethodsService entity. func (amsuo *AllMethodsServiceUpdateOne) Save(ctx context.Context) (*AllMethodsService, error) { - return withHooks[*AllMethodsService, AllMethodsServiceMutation](ctx, amsuo.sqlSave, amsuo.mutation, amsuo.hooks) + return withHooks(ctx, amsuo.sqlSave, amsuo.mutation, amsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/blogpost/where.go b/entproto/internal/entprototest/ent/blogpost/where.go index 13305de0e..1e01832e4 100644 --- a/entproto/internal/entprototest/ent/blogpost/where.go +++ b/entproto/internal/entprototest/ent/blogpost/where.go @@ -286,32 +286,15 @@ func HasCategoriesWith(preds ...predicate.Category) predicate.BlogPost { // And groups predicates with the AND operator between them. func And(predicates ...predicate.BlogPost) predicate.BlogPost { - return predicate.BlogPost(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BlogPost(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.BlogPost) predicate.BlogPost { - return predicate.BlogPost(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.BlogPost(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.BlogPost) predicate.BlogPost { - return predicate.BlogPost(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.BlogPost(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/blogpost_create.go b/entproto/internal/entprototest/ent/blogpost_create.go index 2e6dc9d29..26cb87b67 100644 --- a/entproto/internal/entprototest/ent/blogpost_create.go +++ b/entproto/internal/entprototest/ent/blogpost_create.go @@ -80,7 +80,7 @@ func (bpc *BlogPostCreate) Mutation() *BlogPostMutation { // Save creates the BlogPost in the database. func (bpc *BlogPostCreate) Save(ctx context.Context) (*BlogPost, error) { - return withHooks[*BlogPost, BlogPostMutation](ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) + return withHooks(ctx, bpc.sqlSave, bpc.mutation, bpc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -193,11 +193,15 @@ func (bpc *BlogPostCreate) createSpec() (*BlogPost, *sqlgraph.CreateSpec) { // BlogPostCreateBulk is the builder for creating many BlogPost entities in bulk. type BlogPostCreateBulk struct { config + err error builders []*BlogPostCreate } // Save creates the BlogPost entities in the database. func (bpcb *BlogPostCreateBulk) Save(ctx context.Context) ([]*BlogPost, error) { + if bpcb.err != nil { + return nil, bpcb.err + } specs := make([]*sqlgraph.CreateSpec, len(bpcb.builders)) nodes := make([]*BlogPost, len(bpcb.builders)) mutators := make([]Mutator, len(bpcb.builders)) diff --git a/entproto/internal/entprototest/ent/blogpost_delete.go b/entproto/internal/entprototest/ent/blogpost_delete.go index 4766e3300..b0db08a69 100644 --- a/entproto/internal/entprototest/ent/blogpost_delete.go +++ b/entproto/internal/entprototest/ent/blogpost_delete.go @@ -27,7 +27,7 @@ func (bpd *BlogPostDelete) Where(ps ...predicate.BlogPost) *BlogPostDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (bpd *BlogPostDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, BlogPostMutation](ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) + return withHooks(ctx, bpd.sqlExec, bpd.mutation, bpd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/blogpost_update.go b/entproto/internal/entprototest/ent/blogpost_update.go index 0567dbd9f..47922d683 100644 --- a/entproto/internal/entprototest/ent/blogpost_update.go +++ b/entproto/internal/entprototest/ent/blogpost_update.go @@ -35,12 +35,28 @@ func (bpu *BlogPostUpdate) SetTitle(s string) *BlogPostUpdate { return bpu } +// SetNillableTitle sets the "title" field if the given value is not nil. +func (bpu *BlogPostUpdate) SetNillableTitle(s *string) *BlogPostUpdate { + if s != nil { + bpu.SetTitle(*s) + } + return bpu +} + // SetBody sets the "body" field. func (bpu *BlogPostUpdate) SetBody(s string) *BlogPostUpdate { bpu.mutation.SetBody(s) return bpu } +// SetNillableBody sets the "body" field if the given value is not nil. +func (bpu *BlogPostUpdate) SetNillableBody(s *string) *BlogPostUpdate { + if s != nil { + bpu.SetBody(*s) + } + return bpu +} + // SetExternalID sets the "external_id" field. func (bpu *BlogPostUpdate) SetExternalID(i int) *BlogPostUpdate { bpu.mutation.ResetExternalID() @@ -48,6 +64,14 @@ func (bpu *BlogPostUpdate) SetExternalID(i int) *BlogPostUpdate { return bpu } +// SetNillableExternalID sets the "external_id" field if the given value is not nil. +func (bpu *BlogPostUpdate) SetNillableExternalID(i *int) *BlogPostUpdate { + if i != nil { + bpu.SetExternalID(*i) + } + return bpu +} + // AddExternalID adds i to the "external_id" field. func (bpu *BlogPostUpdate) AddExternalID(i int) *BlogPostUpdate { bpu.mutation.AddExternalID(i) @@ -122,7 +146,7 @@ func (bpu *BlogPostUpdate) RemoveCategories(c ...*Category) *BlogPostUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (bpu *BlogPostUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, BlogPostMutation](ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) + return withHooks(ctx, bpu.sqlSave, bpu.mutation, bpu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -268,12 +292,28 @@ func (bpuo *BlogPostUpdateOne) SetTitle(s string) *BlogPostUpdateOne { return bpuo } +// SetNillableTitle sets the "title" field if the given value is not nil. +func (bpuo *BlogPostUpdateOne) SetNillableTitle(s *string) *BlogPostUpdateOne { + if s != nil { + bpuo.SetTitle(*s) + } + return bpuo +} + // SetBody sets the "body" field. func (bpuo *BlogPostUpdateOne) SetBody(s string) *BlogPostUpdateOne { bpuo.mutation.SetBody(s) return bpuo } +// SetNillableBody sets the "body" field if the given value is not nil. +func (bpuo *BlogPostUpdateOne) SetNillableBody(s *string) *BlogPostUpdateOne { + if s != nil { + bpuo.SetBody(*s) + } + return bpuo +} + // SetExternalID sets the "external_id" field. func (bpuo *BlogPostUpdateOne) SetExternalID(i int) *BlogPostUpdateOne { bpuo.mutation.ResetExternalID() @@ -281,6 +321,14 @@ func (bpuo *BlogPostUpdateOne) SetExternalID(i int) *BlogPostUpdateOne { return bpuo } +// SetNillableExternalID sets the "external_id" field if the given value is not nil. +func (bpuo *BlogPostUpdateOne) SetNillableExternalID(i *int) *BlogPostUpdateOne { + if i != nil { + bpuo.SetExternalID(*i) + } + return bpuo +} + // AddExternalID adds i to the "external_id" field. func (bpuo *BlogPostUpdateOne) AddExternalID(i int) *BlogPostUpdateOne { bpuo.mutation.AddExternalID(i) @@ -368,7 +416,7 @@ func (bpuo *BlogPostUpdateOne) Select(field string, fields ...string) *BlogPostU // Save executes the query and returns the updated BlogPost entity. func (bpuo *BlogPostUpdateOne) Save(ctx context.Context) (*BlogPost, error) { - return withHooks[*BlogPost, BlogPostMutation](ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) + return withHooks(ctx, bpuo.sqlSave, bpuo.mutation, bpuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/category/where.go b/entproto/internal/entprototest/ent/category/where.go index 8c0a7a021..85bfd2831 100644 --- a/entproto/internal/entprototest/ent/category/where.go +++ b/entproto/internal/entprototest/ent/category/where.go @@ -218,32 +218,15 @@ func HasBlogPostsWith(preds ...predicate.BlogPost) predicate.Category { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Category(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Category) predicate.Category { - return predicate.Category(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Category(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/category_create.go b/entproto/internal/entprototest/ent/category_create.go index 9cf6978a5..8db0e51b7 100644 --- a/entproto/internal/entprototest/ent/category_create.go +++ b/entproto/internal/entprototest/ent/category_create.go @@ -54,7 +54,7 @@ func (cc *CategoryCreate) Mutation() *CategoryMutation { // Save creates the Category in the database. func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -143,11 +143,15 @@ func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { // CategoryCreateBulk is the builder for creating many Category entities in bulk. type CategoryCreateBulk struct { config + err error builders []*CategoryCreate } // Save creates the Category entities in the database. func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Category, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) diff --git a/entproto/internal/entprototest/ent/category_delete.go b/entproto/internal/entprototest/ent/category_delete.go index 35ad982ac..c00b51679 100644 --- a/entproto/internal/entprototest/ent/category_delete.go +++ b/entproto/internal/entprototest/ent/category_delete.go @@ -27,7 +27,7 @@ func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/category_update.go b/entproto/internal/entprototest/ent/category_update.go index 742b7e10a..9657a0f77 100644 --- a/entproto/internal/entprototest/ent/category_update.go +++ b/entproto/internal/entprototest/ent/category_update.go @@ -34,12 +34,28 @@ func (cu *CategoryUpdate) SetName(s string) *CategoryUpdate { return cu } +// SetNillableName sets the "name" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableName(s *string) *CategoryUpdate { + if s != nil { + cu.SetName(*s) + } + return cu +} + // SetDescription sets the "description" field. func (cu *CategoryUpdate) SetDescription(s string) *CategoryUpdate { cu.mutation.SetDescription(s) return cu } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableDescription(s *string) *CategoryUpdate { + if s != nil { + cu.SetDescription(*s) + } + return cu +} + // AddBlogPostIDs adds the "blog_posts" edge to the BlogPost entity by IDs. func (cu *CategoryUpdate) AddBlogPostIDs(ids ...int) *CategoryUpdate { cu.mutation.AddBlogPostIDs(ids...) @@ -83,7 +99,7 @@ func (cu *CategoryUpdate) RemoveBlogPosts(b ...*BlogPost) *CategoryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, CategoryMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -194,12 +210,28 @@ func (cuo *CategoryUpdateOne) SetName(s string) *CategoryUpdateOne { return cuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableName(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetName(*s) + } + return cuo +} + // SetDescription sets the "description" field. func (cuo *CategoryUpdateOne) SetDescription(s string) *CategoryUpdateOne { cuo.mutation.SetDescription(s) return cuo } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableDescription(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetDescription(*s) + } + return cuo +} + // AddBlogPostIDs adds the "blog_posts" edge to the BlogPost entity by IDs. func (cuo *CategoryUpdateOne) AddBlogPostIDs(ids ...int) *CategoryUpdateOne { cuo.mutation.AddBlogPostIDs(ids...) @@ -256,7 +288,7 @@ func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUp // Save executes the query and returns the updated Category entity. func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { - return withHooks[*Category, CategoryMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/client.go b/entproto/internal/entprototest/ent/client.go index d77f1dda0..a8a625d40 100644 --- a/entproto/internal/entprototest/ent/client.go +++ b/entproto/internal/entprototest/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entproto/internal/entprototest/ent/migrate" "entgo.io/ent" @@ -198,11 +199,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -426,6 +430,21 @@ func (c *AllMethodsServiceClient) CreateBulk(builders ...*AllMethodsServiceCreat return &AllMethodsServiceCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *AllMethodsServiceClient) MapCreateBulk(slice any, setFunc func(*AllMethodsServiceCreate, int)) *AllMethodsServiceCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AllMethodsServiceCreateBulk{err: fmt.Errorf("calling to AllMethodsServiceClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AllMethodsServiceCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AllMethodsServiceCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for AllMethodsService. func (c *AllMethodsServiceClient) Update() *AllMethodsServiceUpdate { mutation := newAllMethodsServiceMutation(c.config, OpUpdate) @@ -544,6 +563,21 @@ func (c *BlogPostClient) CreateBulk(builders ...*BlogPostCreate) *BlogPostCreate return &BlogPostCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *BlogPostClient) MapCreateBulk(slice any, setFunc func(*BlogPostCreate, int)) *BlogPostCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &BlogPostCreateBulk{err: fmt.Errorf("calling to BlogPostClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*BlogPostCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &BlogPostCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for BlogPost. func (c *BlogPostClient) Update() *BlogPostUpdate { mutation := newBlogPostMutation(c.config, OpUpdate) @@ -694,6 +728,21 @@ func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreate return &CategoryCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) @@ -828,6 +877,21 @@ func (c *DependsOnSkippedClient) CreateBulk(builders ...*DependsOnSkippedCreate) return &DependsOnSkippedCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *DependsOnSkippedClient) MapCreateBulk(slice any, setFunc func(*DependsOnSkippedCreate, int)) *DependsOnSkippedCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &DependsOnSkippedCreateBulk{err: fmt.Errorf("calling to DependsOnSkippedClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*DependsOnSkippedCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &DependsOnSkippedCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for DependsOnSkipped. func (c *DependsOnSkippedClient) Update() *DependsOnSkippedUpdate { mutation := newDependsOnSkippedMutation(c.config, OpUpdate) @@ -962,6 +1026,21 @@ func (c *DuplicateNumberMessageClient) CreateBulk(builders ...*DuplicateNumberMe return &DuplicateNumberMessageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *DuplicateNumberMessageClient) MapCreateBulk(slice any, setFunc func(*DuplicateNumberMessageCreate, int)) *DuplicateNumberMessageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &DuplicateNumberMessageCreateBulk{err: fmt.Errorf("calling to DuplicateNumberMessageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*DuplicateNumberMessageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &DuplicateNumberMessageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for DuplicateNumberMessage. func (c *DuplicateNumberMessageClient) Update() *DuplicateNumberMessageUpdate { mutation := newDuplicateNumberMessageMutation(c.config, OpUpdate) @@ -1080,6 +1159,21 @@ func (c *EnumWithConflictingValueClient) CreateBulk(builders ...*EnumWithConflic return &EnumWithConflictingValueCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *EnumWithConflictingValueClient) MapCreateBulk(slice any, setFunc func(*EnumWithConflictingValueCreate, int)) *EnumWithConflictingValueCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &EnumWithConflictingValueCreateBulk{err: fmt.Errorf("calling to EnumWithConflictingValueClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*EnumWithConflictingValueCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &EnumWithConflictingValueCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for EnumWithConflictingValue. func (c *EnumWithConflictingValueClient) Update() *EnumWithConflictingValueUpdate { mutation := newEnumWithConflictingValueMutation(c.config, OpUpdate) @@ -1198,6 +1292,21 @@ func (c *ExplicitSkippedMessageClient) CreateBulk(builders ...*ExplicitSkippedMe return &ExplicitSkippedMessageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ExplicitSkippedMessageClient) MapCreateBulk(slice any, setFunc func(*ExplicitSkippedMessageCreate, int)) *ExplicitSkippedMessageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ExplicitSkippedMessageCreateBulk{err: fmt.Errorf("calling to ExplicitSkippedMessageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ExplicitSkippedMessageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ExplicitSkippedMessageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for ExplicitSkippedMessage. func (c *ExplicitSkippedMessageClient) Update() *ExplicitSkippedMessageUpdate { mutation := newExplicitSkippedMessageMutation(c.config, OpUpdate) @@ -1316,6 +1425,21 @@ func (c *ImageClient) CreateBulk(builders ...*ImageCreate) *ImageCreateBulk { return &ImageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ImageClient) MapCreateBulk(slice any, setFunc func(*ImageCreate, int)) *ImageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ImageCreateBulk{err: fmt.Errorf("calling to ImageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ImageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ImageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Image. func (c *ImageClient) Update() *ImageUpdate { mutation := newImageMutation(c.config, OpUpdate) @@ -1450,6 +1574,21 @@ func (c *ImplicitSkippedMessageClient) CreateBulk(builders ...*ImplicitSkippedMe return &ImplicitSkippedMessageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ImplicitSkippedMessageClient) MapCreateBulk(slice any, setFunc func(*ImplicitSkippedMessageCreate, int)) *ImplicitSkippedMessageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ImplicitSkippedMessageCreateBulk{err: fmt.Errorf("calling to ImplicitSkippedMessageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ImplicitSkippedMessageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ImplicitSkippedMessageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for ImplicitSkippedMessage. func (c *ImplicitSkippedMessageClient) Update() *ImplicitSkippedMessageUpdate { mutation := newImplicitSkippedMessageMutation(c.config, OpUpdate) @@ -1568,6 +1707,21 @@ func (c *InvalidFieldMessageClient) CreateBulk(builders ...*InvalidFieldMessageC return &InvalidFieldMessageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *InvalidFieldMessageClient) MapCreateBulk(slice any, setFunc func(*InvalidFieldMessageCreate, int)) *InvalidFieldMessageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &InvalidFieldMessageCreateBulk{err: fmt.Errorf("calling to InvalidFieldMessageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*InvalidFieldMessageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &InvalidFieldMessageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for InvalidFieldMessage. func (c *InvalidFieldMessageClient) Update() *InvalidFieldMessageUpdate { mutation := newInvalidFieldMessageMutation(c.config, OpUpdate) @@ -1686,6 +1840,21 @@ func (c *MessageWithEnumClient) CreateBulk(builders ...*MessageWithEnumCreate) * return &MessageWithEnumCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageWithEnumClient) MapCreateBulk(slice any, setFunc func(*MessageWithEnumCreate, int)) *MessageWithEnumCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageWithEnumCreateBulk{err: fmt.Errorf("calling to MessageWithEnumClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageWithEnumCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageWithEnumCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MessageWithEnum. func (c *MessageWithEnumClient) Update() *MessageWithEnumUpdate { mutation := newMessageWithEnumMutation(c.config, OpUpdate) @@ -1804,6 +1973,21 @@ func (c *MessageWithFieldOneClient) CreateBulk(builders ...*MessageWithFieldOneC return &MessageWithFieldOneCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageWithFieldOneClient) MapCreateBulk(slice any, setFunc func(*MessageWithFieldOneCreate, int)) *MessageWithFieldOneCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageWithFieldOneCreateBulk{err: fmt.Errorf("calling to MessageWithFieldOneClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageWithFieldOneCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageWithFieldOneCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MessageWithFieldOne. func (c *MessageWithFieldOneClient) Update() *MessageWithFieldOneUpdate { mutation := newMessageWithFieldOneMutation(c.config, OpUpdate) @@ -1922,6 +2106,21 @@ func (c *MessageWithIDClient) CreateBulk(builders ...*MessageWithIDCreate) *Mess return &MessageWithIDCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageWithIDClient) MapCreateBulk(slice any, setFunc func(*MessageWithIDCreate, int)) *MessageWithIDCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageWithIDCreateBulk{err: fmt.Errorf("calling to MessageWithIDClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageWithIDCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageWithIDCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MessageWithID. func (c *MessageWithIDClient) Update() *MessageWithIDUpdate { mutation := newMessageWithIDMutation(c.config, OpUpdate) @@ -2040,6 +2239,21 @@ func (c *MessageWithIntsClient) CreateBulk(builders ...*MessageWithIntsCreate) * return &MessageWithIntsCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageWithIntsClient) MapCreateBulk(slice any, setFunc func(*MessageWithIntsCreate, int)) *MessageWithIntsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageWithIntsCreateBulk{err: fmt.Errorf("calling to MessageWithIntsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageWithIntsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageWithIntsCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MessageWithInts. func (c *MessageWithIntsClient) Update() *MessageWithIntsUpdate { mutation := newMessageWithIntsMutation(c.config, OpUpdate) @@ -2158,6 +2372,21 @@ func (c *MessageWithOptionalsClient) CreateBulk(builders ...*MessageWithOptional return &MessageWithOptionalsCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageWithOptionalsClient) MapCreateBulk(slice any, setFunc func(*MessageWithOptionalsCreate, int)) *MessageWithOptionalsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageWithOptionalsCreateBulk{err: fmt.Errorf("calling to MessageWithOptionalsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageWithOptionalsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageWithOptionalsCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MessageWithOptionals. func (c *MessageWithOptionalsClient) Update() *MessageWithOptionalsUpdate { mutation := newMessageWithOptionalsMutation(c.config, OpUpdate) @@ -2276,6 +2505,21 @@ func (c *MessageWithPackageNameClient) CreateBulk(builders ...*MessageWithPackag return &MessageWithPackageNameCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageWithPackageNameClient) MapCreateBulk(slice any, setFunc func(*MessageWithPackageNameCreate, int)) *MessageWithPackageNameCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageWithPackageNameCreateBulk{err: fmt.Errorf("calling to MessageWithPackageNameClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageWithPackageNameCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageWithPackageNameCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MessageWithPackageName. func (c *MessageWithPackageNameClient) Update() *MessageWithPackageNameUpdate { mutation := newMessageWithPackageNameMutation(c.config, OpUpdate) @@ -2394,6 +2638,21 @@ func (c *MessageWithStringsClient) CreateBulk(builders ...*MessageWithStringsCre return &MessageWithStringsCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageWithStringsClient) MapCreateBulk(slice any, setFunc func(*MessageWithStringsCreate, int)) *MessageWithStringsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageWithStringsCreateBulk{err: fmt.Errorf("calling to MessageWithStringsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageWithStringsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageWithStringsCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MessageWithStrings. func (c *MessageWithStringsClient) Update() *MessageWithStringsUpdate { mutation := newMessageWithStringsMutation(c.config, OpUpdate) @@ -2512,6 +2771,21 @@ func (c *NoBackrefClient) CreateBulk(builders ...*NoBackrefCreate) *NoBackrefCre return &NoBackrefCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *NoBackrefClient) MapCreateBulk(slice any, setFunc func(*NoBackrefCreate, int)) *NoBackrefCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &NoBackrefCreateBulk{err: fmt.Errorf("calling to NoBackrefClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*NoBackrefCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &NoBackrefCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for NoBackref. func (c *NoBackrefClient) Update() *NoBackrefUpdate { mutation := newNoBackrefMutation(c.config, OpUpdate) @@ -2646,6 +2920,21 @@ func (c *OneMethodServiceClient) CreateBulk(builders ...*OneMethodServiceCreate) return &OneMethodServiceCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *OneMethodServiceClient) MapCreateBulk(slice any, setFunc func(*OneMethodServiceCreate, int)) *OneMethodServiceCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &OneMethodServiceCreateBulk{err: fmt.Errorf("calling to OneMethodServiceClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*OneMethodServiceCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &OneMethodServiceCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for OneMethodService. func (c *OneMethodServiceClient) Update() *OneMethodServiceUpdate { mutation := newOneMethodServiceMutation(c.config, OpUpdate) @@ -2764,6 +3053,21 @@ func (c *PortalClient) CreateBulk(builders ...*PortalCreate) *PortalCreateBulk { return &PortalCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PortalClient) MapCreateBulk(slice any, setFunc func(*PortalCreate, int)) *PortalCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PortalCreateBulk{err: fmt.Errorf("calling to PortalClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PortalCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PortalCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Portal. func (c *PortalClient) Update() *PortalUpdate { mutation := newPortalMutation(c.config, OpUpdate) @@ -2898,6 +3202,21 @@ func (c *SkipEdgeExampleClient) CreateBulk(builders ...*SkipEdgeExampleCreate) * return &SkipEdgeExampleCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *SkipEdgeExampleClient) MapCreateBulk(slice any, setFunc func(*SkipEdgeExampleCreate, int)) *SkipEdgeExampleCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SkipEdgeExampleCreateBulk{err: fmt.Errorf("calling to SkipEdgeExampleClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SkipEdgeExampleCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SkipEdgeExampleCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for SkipEdgeExample. func (c *SkipEdgeExampleClient) Update() *SkipEdgeExampleUpdate { mutation := newSkipEdgeExampleMutation(c.config, OpUpdate) @@ -3032,6 +3351,21 @@ func (c *TwoMethodServiceClient) CreateBulk(builders ...*TwoMethodServiceCreate) return &TwoMethodServiceCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TwoMethodServiceClient) MapCreateBulk(slice any, setFunc func(*TwoMethodServiceCreate, int)) *TwoMethodServiceCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TwoMethodServiceCreateBulk{err: fmt.Errorf("calling to TwoMethodServiceClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TwoMethodServiceCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TwoMethodServiceCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for TwoMethodService. func (c *TwoMethodServiceClient) Update() *TwoMethodServiceUpdate { mutation := newTwoMethodServiceMutation(c.config, OpUpdate) @@ -3150,6 +3484,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) @@ -3316,6 +3665,21 @@ func (c *ValidMessageClient) CreateBulk(builders ...*ValidMessageCreate) *ValidM return &ValidMessageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ValidMessageClient) MapCreateBulk(slice any, setFunc func(*ValidMessageCreate, int)) *ValidMessageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ValidMessageCreateBulk{err: fmt.Errorf("calling to ValidMessageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ValidMessageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ValidMessageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for ValidMessage. func (c *ValidMessageClient) Update() *ValidMessageUpdate { mutation := newValidMessageMutation(c.config, OpUpdate) diff --git a/entproto/internal/entprototest/ent/dependsonskipped/where.go b/entproto/internal/entprototest/ent/dependsonskipped/where.go index 8ea1613cf..34c0721a4 100644 --- a/entproto/internal/entprototest/ent/dependsonskipped/where.go +++ b/entproto/internal/entprototest/ent/dependsonskipped/where.go @@ -148,32 +148,15 @@ func HasSkippedWith(preds ...predicate.ImplicitSkippedMessage) predicate.Depends // And groups predicates with the AND operator between them. func And(predicates ...predicate.DependsOnSkipped) predicate.DependsOnSkipped { - return predicate.DependsOnSkipped(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.DependsOnSkipped(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.DependsOnSkipped) predicate.DependsOnSkipped { - return predicate.DependsOnSkipped(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.DependsOnSkipped(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.DependsOnSkipped) predicate.DependsOnSkipped { - return predicate.DependsOnSkipped(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.DependsOnSkipped(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/dependsonskipped_create.go b/entproto/internal/entprototest/ent/dependsonskipped_create.go index 33a1a6643..54f3cb290 100644 --- a/entproto/internal/entprototest/ent/dependsonskipped_create.go +++ b/entproto/internal/entprototest/ent/dependsonskipped_create.go @@ -48,7 +48,7 @@ func (dosc *DependsOnSkippedCreate) Mutation() *DependsOnSkippedMutation { // Save creates the DependsOnSkipped in the database. func (dosc *DependsOnSkippedCreate) Save(ctx context.Context) (*DependsOnSkipped, error) { - return withHooks[*DependsOnSkipped, DependsOnSkippedMutation](ctx, dosc.sqlSave, dosc.mutation, dosc.hooks) + return withHooks(ctx, dosc.sqlSave, dosc.mutation, dosc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -130,11 +130,15 @@ func (dosc *DependsOnSkippedCreate) createSpec() (*DependsOnSkipped, *sqlgraph.C // DependsOnSkippedCreateBulk is the builder for creating many DependsOnSkipped entities in bulk. type DependsOnSkippedCreateBulk struct { config + err error builders []*DependsOnSkippedCreate } // Save creates the DependsOnSkipped entities in the database. func (doscb *DependsOnSkippedCreateBulk) Save(ctx context.Context) ([]*DependsOnSkipped, error) { + if doscb.err != nil { + return nil, doscb.err + } specs := make([]*sqlgraph.CreateSpec, len(doscb.builders)) nodes := make([]*DependsOnSkipped, len(doscb.builders)) mutators := make([]Mutator, len(doscb.builders)) diff --git a/entproto/internal/entprototest/ent/dependsonskipped_delete.go b/entproto/internal/entprototest/ent/dependsonskipped_delete.go index bdc611961..e9be096df 100644 --- a/entproto/internal/entprototest/ent/dependsonskipped_delete.go +++ b/entproto/internal/entprototest/ent/dependsonskipped_delete.go @@ -27,7 +27,7 @@ func (dosd *DependsOnSkippedDelete) Where(ps ...predicate.DependsOnSkipped) *Dep // Exec executes the deletion query and returns how many vertices were deleted. func (dosd *DependsOnSkippedDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, DependsOnSkippedMutation](ctx, dosd.sqlExec, dosd.mutation, dosd.hooks) + return withHooks(ctx, dosd.sqlExec, dosd.mutation, dosd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/dependsonskipped_update.go b/entproto/internal/entprototest/ent/dependsonskipped_update.go index 0722b9a4f..b9d6fc071 100644 --- a/entproto/internal/entprototest/ent/dependsonskipped_update.go +++ b/entproto/internal/entprototest/ent/dependsonskipped_update.go @@ -34,6 +34,14 @@ func (dosu *DependsOnSkippedUpdate) SetName(s string) *DependsOnSkippedUpdate { return dosu } +// SetNillableName sets the "name" field if the given value is not nil. +func (dosu *DependsOnSkippedUpdate) SetNillableName(s *string) *DependsOnSkippedUpdate { + if s != nil { + dosu.SetName(*s) + } + return dosu +} + // AddSkippedIDs adds the "skipped" edge to the ImplicitSkippedMessage entity by IDs. func (dosu *DependsOnSkippedUpdate) AddSkippedIDs(ids ...int) *DependsOnSkippedUpdate { dosu.mutation.AddSkippedIDs(ids...) @@ -77,7 +85,7 @@ func (dosu *DependsOnSkippedUpdate) RemoveSkipped(i ...*ImplicitSkippedMessage) // Save executes the query and returns the number of nodes affected by the update operation. func (dosu *DependsOnSkippedUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, DependsOnSkippedMutation](ctx, dosu.sqlSave, dosu.mutation, dosu.hooks) + return withHooks(ctx, dosu.sqlSave, dosu.mutation, dosu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -185,6 +193,14 @@ func (dosuo *DependsOnSkippedUpdateOne) SetName(s string) *DependsOnSkippedUpdat return dosuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (dosuo *DependsOnSkippedUpdateOne) SetNillableName(s *string) *DependsOnSkippedUpdateOne { + if s != nil { + dosuo.SetName(*s) + } + return dosuo +} + // AddSkippedIDs adds the "skipped" edge to the ImplicitSkippedMessage entity by IDs. func (dosuo *DependsOnSkippedUpdateOne) AddSkippedIDs(ids ...int) *DependsOnSkippedUpdateOne { dosuo.mutation.AddSkippedIDs(ids...) @@ -241,7 +257,7 @@ func (dosuo *DependsOnSkippedUpdateOne) Select(field string, fields ...string) * // Save executes the query and returns the updated DependsOnSkipped entity. func (dosuo *DependsOnSkippedUpdateOne) Save(ctx context.Context) (*DependsOnSkipped, error) { - return withHooks[*DependsOnSkipped, DependsOnSkippedMutation](ctx, dosuo.sqlSave, dosuo.mutation, dosuo.hooks) + return withHooks(ctx, dosuo.sqlSave, dosuo.mutation, dosuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/duplicatenumbermessage/where.go b/entproto/internal/entprototest/ent/duplicatenumbermessage/where.go index 628e57f51..6bf2adad1 100644 --- a/entproto/internal/entprototest/ent/duplicatenumbermessage/where.go +++ b/entproto/internal/entprototest/ent/duplicatenumbermessage/where.go @@ -194,32 +194,15 @@ func WorldContainsFold(v string) predicate.DuplicateNumberMessage { // And groups predicates with the AND operator between them. func And(predicates ...predicate.DuplicateNumberMessage) predicate.DuplicateNumberMessage { - return predicate.DuplicateNumberMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.DuplicateNumberMessage(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.DuplicateNumberMessage) predicate.DuplicateNumberMessage { - return predicate.DuplicateNumberMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.DuplicateNumberMessage(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.DuplicateNumberMessage) predicate.DuplicateNumberMessage { - return predicate.DuplicateNumberMessage(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.DuplicateNumberMessage(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/duplicatenumbermessage_create.go b/entproto/internal/entprototest/ent/duplicatenumbermessage_create.go index 271575231..b731a85e3 100644 --- a/entproto/internal/entprototest/ent/duplicatenumbermessage_create.go +++ b/entproto/internal/entprototest/ent/duplicatenumbermessage_create.go @@ -38,7 +38,7 @@ func (dnmc *DuplicateNumberMessageCreate) Mutation() *DuplicateNumberMessageMuta // Save creates the DuplicateNumberMessage in the database. func (dnmc *DuplicateNumberMessageCreate) Save(ctx context.Context) (*DuplicateNumberMessage, error) { - return withHooks[*DuplicateNumberMessage, DuplicateNumberMessageMutation](ctx, dnmc.sqlSave, dnmc.mutation, dnmc.hooks) + return withHooks(ctx, dnmc.sqlSave, dnmc.mutation, dnmc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -111,11 +111,15 @@ func (dnmc *DuplicateNumberMessageCreate) createSpec() (*DuplicateNumberMessage, // DuplicateNumberMessageCreateBulk is the builder for creating many DuplicateNumberMessage entities in bulk. type DuplicateNumberMessageCreateBulk struct { config + err error builders []*DuplicateNumberMessageCreate } // Save creates the DuplicateNumberMessage entities in the database. func (dnmcb *DuplicateNumberMessageCreateBulk) Save(ctx context.Context) ([]*DuplicateNumberMessage, error) { + if dnmcb.err != nil { + return nil, dnmcb.err + } specs := make([]*sqlgraph.CreateSpec, len(dnmcb.builders)) nodes := make([]*DuplicateNumberMessage, len(dnmcb.builders)) mutators := make([]Mutator, len(dnmcb.builders)) diff --git a/entproto/internal/entprototest/ent/duplicatenumbermessage_delete.go b/entproto/internal/entprototest/ent/duplicatenumbermessage_delete.go index 0e763c00d..c040002f1 100644 --- a/entproto/internal/entprototest/ent/duplicatenumbermessage_delete.go +++ b/entproto/internal/entprototest/ent/duplicatenumbermessage_delete.go @@ -27,7 +27,7 @@ func (dnmd *DuplicateNumberMessageDelete) Where(ps ...predicate.DuplicateNumberM // Exec executes the deletion query and returns how many vertices were deleted. func (dnmd *DuplicateNumberMessageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, DuplicateNumberMessageMutation](ctx, dnmd.sqlExec, dnmd.mutation, dnmd.hooks) + return withHooks(ctx, dnmd.sqlExec, dnmd.mutation, dnmd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/duplicatenumbermessage_update.go b/entproto/internal/entprototest/ent/duplicatenumbermessage_update.go index ee855339a..208d3f7e1 100644 --- a/entproto/internal/entprototest/ent/duplicatenumbermessage_update.go +++ b/entproto/internal/entprototest/ent/duplicatenumbermessage_update.go @@ -33,12 +33,28 @@ func (dnmu *DuplicateNumberMessageUpdate) SetHello(s string) *DuplicateNumberMes return dnmu } +// SetNillableHello sets the "hello" field if the given value is not nil. +func (dnmu *DuplicateNumberMessageUpdate) SetNillableHello(s *string) *DuplicateNumberMessageUpdate { + if s != nil { + dnmu.SetHello(*s) + } + return dnmu +} + // SetWorld sets the "world" field. func (dnmu *DuplicateNumberMessageUpdate) SetWorld(s string) *DuplicateNumberMessageUpdate { dnmu.mutation.SetWorld(s) return dnmu } +// SetNillableWorld sets the "world" field if the given value is not nil. +func (dnmu *DuplicateNumberMessageUpdate) SetNillableWorld(s *string) *DuplicateNumberMessageUpdate { + if s != nil { + dnmu.SetWorld(*s) + } + return dnmu +} + // Mutation returns the DuplicateNumberMessageMutation object of the builder. func (dnmu *DuplicateNumberMessageUpdate) Mutation() *DuplicateNumberMessageMutation { return dnmu.mutation @@ -46,7 +62,7 @@ func (dnmu *DuplicateNumberMessageUpdate) Mutation() *DuplicateNumberMessageMuta // Save executes the query and returns the number of nodes affected by the update operation. func (dnmu *DuplicateNumberMessageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, DuplicateNumberMessageMutation](ctx, dnmu.sqlSave, dnmu.mutation, dnmu.hooks) + return withHooks(ctx, dnmu.sqlSave, dnmu.mutation, dnmu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -112,12 +128,28 @@ func (dnmuo *DuplicateNumberMessageUpdateOne) SetHello(s string) *DuplicateNumbe return dnmuo } +// SetNillableHello sets the "hello" field if the given value is not nil. +func (dnmuo *DuplicateNumberMessageUpdateOne) SetNillableHello(s *string) *DuplicateNumberMessageUpdateOne { + if s != nil { + dnmuo.SetHello(*s) + } + return dnmuo +} + // SetWorld sets the "world" field. func (dnmuo *DuplicateNumberMessageUpdateOne) SetWorld(s string) *DuplicateNumberMessageUpdateOne { dnmuo.mutation.SetWorld(s) return dnmuo } +// SetNillableWorld sets the "world" field if the given value is not nil. +func (dnmuo *DuplicateNumberMessageUpdateOne) SetNillableWorld(s *string) *DuplicateNumberMessageUpdateOne { + if s != nil { + dnmuo.SetWorld(*s) + } + return dnmuo +} + // Mutation returns the DuplicateNumberMessageMutation object of the builder. func (dnmuo *DuplicateNumberMessageUpdateOne) Mutation() *DuplicateNumberMessageMutation { return dnmuo.mutation @@ -138,7 +170,7 @@ func (dnmuo *DuplicateNumberMessageUpdateOne) Select(field string, fields ...str // Save executes the query and returns the updated DuplicateNumberMessage entity. func (dnmuo *DuplicateNumberMessageUpdateOne) Save(ctx context.Context) (*DuplicateNumberMessage, error) { - return withHooks[*DuplicateNumberMessage, DuplicateNumberMessageMutation](ctx, dnmuo.sqlSave, dnmuo.mutation, dnmuo.hooks) + return withHooks(ctx, dnmuo.sqlSave, dnmuo.mutation, dnmuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue/where.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue/where.go index 5e7f32408..e1fae68b2 100644 --- a/entproto/internal/entprototest/ent/enumwithconflictingvalue/where.go +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue/where.go @@ -74,32 +74,15 @@ func EnumNotIn(vs ...Enum) predicate.EnumWithConflictingValue { // And groups predicates with the AND operator between them. func And(predicates ...predicate.EnumWithConflictingValue) predicate.EnumWithConflictingValue { - return predicate.EnumWithConflictingValue(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.EnumWithConflictingValue(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.EnumWithConflictingValue) predicate.EnumWithConflictingValue { - return predicate.EnumWithConflictingValue(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.EnumWithConflictingValue(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.EnumWithConflictingValue) predicate.EnumWithConflictingValue { - return predicate.EnumWithConflictingValue(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.EnumWithConflictingValue(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue_create.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue_create.go index 883816782..e20e7a841 100644 --- a/entproto/internal/entprototest/ent/enumwithconflictingvalue_create.go +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue_create.go @@ -32,7 +32,7 @@ func (ewcvc *EnumWithConflictingValueCreate) Mutation() *EnumWithConflictingValu // Save creates the EnumWithConflictingValue in the database. func (ewcvc *EnumWithConflictingValueCreate) Save(ctx context.Context) (*EnumWithConflictingValue, error) { - return withHooks[*EnumWithConflictingValue, EnumWithConflictingValueMutation](ctx, ewcvc.sqlSave, ewcvc.mutation, ewcvc.hooks) + return withHooks(ctx, ewcvc.sqlSave, ewcvc.mutation, ewcvc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -103,11 +103,15 @@ func (ewcvc *EnumWithConflictingValueCreate) createSpec() (*EnumWithConflictingV // EnumWithConflictingValueCreateBulk is the builder for creating many EnumWithConflictingValue entities in bulk. type EnumWithConflictingValueCreateBulk struct { config + err error builders []*EnumWithConflictingValueCreate } // Save creates the EnumWithConflictingValue entities in the database. func (ewcvcb *EnumWithConflictingValueCreateBulk) Save(ctx context.Context) ([]*EnumWithConflictingValue, error) { + if ewcvcb.err != nil { + return nil, ewcvcb.err + } specs := make([]*sqlgraph.CreateSpec, len(ewcvcb.builders)) nodes := make([]*EnumWithConflictingValue, len(ewcvcb.builders)) mutators := make([]Mutator, len(ewcvcb.builders)) diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue_delete.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue_delete.go index 66d6841db..1d5f12a7a 100644 --- a/entproto/internal/entprototest/ent/enumwithconflictingvalue_delete.go +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue_delete.go @@ -27,7 +27,7 @@ func (ewcvd *EnumWithConflictingValueDelete) Where(ps ...predicate.EnumWithConfl // Exec executes the deletion query and returns how many vertices were deleted. func (ewcvd *EnumWithConflictingValueDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, EnumWithConflictingValueMutation](ctx, ewcvd.sqlExec, ewcvd.mutation, ewcvd.hooks) + return withHooks(ctx, ewcvd.sqlExec, ewcvd.mutation, ewcvd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue_update.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue_update.go index b28937758..bdd4503f4 100644 --- a/entproto/internal/entprototest/ent/enumwithconflictingvalue_update.go +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue_update.go @@ -33,6 +33,14 @@ func (ewcvu *EnumWithConflictingValueUpdate) SetEnum(e enumwithconflictingvalue. return ewcvu } +// SetNillableEnum sets the "enum" field if the given value is not nil. +func (ewcvu *EnumWithConflictingValueUpdate) SetNillableEnum(e *enumwithconflictingvalue.Enum) *EnumWithConflictingValueUpdate { + if e != nil { + ewcvu.SetEnum(*e) + } + return ewcvu +} + // Mutation returns the EnumWithConflictingValueMutation object of the builder. func (ewcvu *EnumWithConflictingValueUpdate) Mutation() *EnumWithConflictingValueMutation { return ewcvu.mutation @@ -40,7 +48,7 @@ func (ewcvu *EnumWithConflictingValueUpdate) Mutation() *EnumWithConflictingValu // Save executes the query and returns the number of nodes affected by the update operation. func (ewcvu *EnumWithConflictingValueUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, EnumWithConflictingValueMutation](ctx, ewcvu.sqlSave, ewcvu.mutation, ewcvu.hooks) + return withHooks(ctx, ewcvu.sqlSave, ewcvu.mutation, ewcvu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -116,6 +124,14 @@ func (ewcvuo *EnumWithConflictingValueUpdateOne) SetEnum(e enumwithconflictingva return ewcvuo } +// SetNillableEnum sets the "enum" field if the given value is not nil. +func (ewcvuo *EnumWithConflictingValueUpdateOne) SetNillableEnum(e *enumwithconflictingvalue.Enum) *EnumWithConflictingValueUpdateOne { + if e != nil { + ewcvuo.SetEnum(*e) + } + return ewcvuo +} + // Mutation returns the EnumWithConflictingValueMutation object of the builder. func (ewcvuo *EnumWithConflictingValueUpdateOne) Mutation() *EnumWithConflictingValueMutation { return ewcvuo.mutation @@ -136,7 +152,7 @@ func (ewcvuo *EnumWithConflictingValueUpdateOne) Select(field string, fields ... // Save executes the query and returns the updated EnumWithConflictingValue entity. func (ewcvuo *EnumWithConflictingValueUpdateOne) Save(ctx context.Context) (*EnumWithConflictingValue, error) { - return withHooks[*EnumWithConflictingValue, EnumWithConflictingValueMutation](ctx, ewcvuo.sqlSave, ewcvuo.mutation, ewcvuo.hooks) + return withHooks(ctx, ewcvuo.sqlSave, ewcvuo.mutation, ewcvuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/explicitskippedmessage/where.go b/entproto/internal/entprototest/ent/explicitskippedmessage/where.go index 655255de0..4bc40f845 100644 --- a/entproto/internal/entprototest/ent/explicitskippedmessage/where.go +++ b/entproto/internal/entprototest/ent/explicitskippedmessage/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.ExplicitSkippedMessage { // And groups predicates with the AND operator between them. func And(predicates ...predicate.ExplicitSkippedMessage) predicate.ExplicitSkippedMessage { - return predicate.ExplicitSkippedMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.ExplicitSkippedMessage(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.ExplicitSkippedMessage) predicate.ExplicitSkippedMessage { - return predicate.ExplicitSkippedMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.ExplicitSkippedMessage(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.ExplicitSkippedMessage) predicate.ExplicitSkippedMessage { - return predicate.ExplicitSkippedMessage(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.ExplicitSkippedMessage(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/explicitskippedmessage_create.go b/entproto/internal/entprototest/ent/explicitskippedmessage_create.go index e38d9c337..037d7e6a6 100644 --- a/entproto/internal/entprototest/ent/explicitskippedmessage_create.go +++ b/entproto/internal/entprototest/ent/explicitskippedmessage_create.go @@ -25,7 +25,7 @@ func (esmc *ExplicitSkippedMessageCreate) Mutation() *ExplicitSkippedMessageMuta // Save creates the ExplicitSkippedMessage in the database. func (esmc *ExplicitSkippedMessageCreate) Save(ctx context.Context) (*ExplicitSkippedMessage, error) { - return withHooks[*ExplicitSkippedMessage, ExplicitSkippedMessageMutation](ctx, esmc.sqlSave, esmc.mutation, esmc.hooks) + return withHooks(ctx, esmc.sqlSave, esmc.mutation, esmc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (esmc *ExplicitSkippedMessageCreate) createSpec() (*ExplicitSkippedMessage, // ExplicitSkippedMessageCreateBulk is the builder for creating many ExplicitSkippedMessage entities in bulk. type ExplicitSkippedMessageCreateBulk struct { config + err error builders []*ExplicitSkippedMessageCreate } // Save creates the ExplicitSkippedMessage entities in the database. func (esmcb *ExplicitSkippedMessageCreateBulk) Save(ctx context.Context) ([]*ExplicitSkippedMessage, error) { + if esmcb.err != nil { + return nil, esmcb.err + } specs := make([]*sqlgraph.CreateSpec, len(esmcb.builders)) nodes := make([]*ExplicitSkippedMessage, len(esmcb.builders)) mutators := make([]Mutator, len(esmcb.builders)) diff --git a/entproto/internal/entprototest/ent/explicitskippedmessage_delete.go b/entproto/internal/entprototest/ent/explicitskippedmessage_delete.go index 493420ef9..835be07db 100644 --- a/entproto/internal/entprototest/ent/explicitskippedmessage_delete.go +++ b/entproto/internal/entprototest/ent/explicitskippedmessage_delete.go @@ -27,7 +27,7 @@ func (esmd *ExplicitSkippedMessageDelete) Where(ps ...predicate.ExplicitSkippedM // Exec executes the deletion query and returns how many vertices were deleted. func (esmd *ExplicitSkippedMessageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, ExplicitSkippedMessageMutation](ctx, esmd.sqlExec, esmd.mutation, esmd.hooks) + return withHooks(ctx, esmd.sqlExec, esmd.mutation, esmd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/explicitskippedmessage_update.go b/entproto/internal/entprototest/ent/explicitskippedmessage_update.go index 93c61f1eb..d30055f3b 100644 --- a/entproto/internal/entprototest/ent/explicitskippedmessage_update.go +++ b/entproto/internal/entprototest/ent/explicitskippedmessage_update.go @@ -34,7 +34,7 @@ func (esmu *ExplicitSkippedMessageUpdate) Mutation() *ExplicitSkippedMessageMuta // Save executes the query and returns the number of nodes affected by the update operation. func (esmu *ExplicitSkippedMessageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, ExplicitSkippedMessageMutation](ctx, esmu.sqlSave, esmu.mutation, esmu.hooks) + return withHooks(ctx, esmu.sqlSave, esmu.mutation, esmu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (esmuo *ExplicitSkippedMessageUpdateOne) Select(field string, fields ...str // Save executes the query and returns the updated ExplicitSkippedMessage entity. func (esmuo *ExplicitSkippedMessageUpdateOne) Save(ctx context.Context) (*ExplicitSkippedMessage, error) { - return withHooks[*ExplicitSkippedMessage, ExplicitSkippedMessageMutation](ctx, esmuo.sqlSave, esmuo.mutation, esmuo.hooks) + return withHooks(ctx, esmuo.sqlSave, esmuo.mutation, esmuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/image/where.go b/entproto/internal/entprototest/ent/image/where.go index 95b6874ab..c0c2541dc 100644 --- a/entproto/internal/entprototest/ent/image/where.go +++ b/entproto/internal/entprototest/ent/image/where.go @@ -149,32 +149,15 @@ func HasUserProfilePicWith(preds ...predicate.User) predicate.Image { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Image) predicate.Image { - return predicate.Image(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Image(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Image) predicate.Image { - return predicate.Image(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Image(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Image) predicate.Image { - return predicate.Image(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Image(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/image_create.go b/entproto/internal/entprototest/ent/image_create.go index 94c581da9..23d5803e1 100644 --- a/entproto/internal/entprototest/ent/image_create.go +++ b/entproto/internal/entprototest/ent/image_create.go @@ -55,7 +55,7 @@ func (ic *ImageCreate) Mutation() *ImageMutation { // Save creates the Image in the database. func (ic *ImageCreate) Save(ctx context.Context) (*Image, error) { - return withHooks[*Image, ImageMutation](ctx, ic.sqlSave, ic.mutation, ic.hooks) + return withHooks(ctx, ic.sqlSave, ic.mutation, ic.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -146,11 +146,15 @@ func (ic *ImageCreate) createSpec() (*Image, *sqlgraph.CreateSpec) { // ImageCreateBulk is the builder for creating many Image entities in bulk. type ImageCreateBulk struct { config + err error builders []*ImageCreate } // Save creates the Image entities in the database. func (icb *ImageCreateBulk) Save(ctx context.Context) ([]*Image, error) { + if icb.err != nil { + return nil, icb.err + } specs := make([]*sqlgraph.CreateSpec, len(icb.builders)) nodes := make([]*Image, len(icb.builders)) mutators := make([]Mutator, len(icb.builders)) diff --git a/entproto/internal/entprototest/ent/image_delete.go b/entproto/internal/entprototest/ent/image_delete.go index 7d99eda87..105239bf1 100644 --- a/entproto/internal/entprototest/ent/image_delete.go +++ b/entproto/internal/entprototest/ent/image_delete.go @@ -27,7 +27,7 @@ func (id *ImageDelete) Where(ps ...predicate.Image) *ImageDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (id *ImageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, ImageMutation](ctx, id.sqlExec, id.mutation, id.hooks) + return withHooks(ctx, id.sqlExec, id.mutation, id.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/image_update.go b/entproto/internal/entprototest/ent/image_update.go index b37c9fbec..74835c21c 100644 --- a/entproto/internal/entprototest/ent/image_update.go +++ b/entproto/internal/entprototest/ent/image_update.go @@ -34,6 +34,14 @@ func (iu *ImageUpdate) SetURLPath(s string) *ImageUpdate { return iu } +// SetNillableURLPath sets the "url_path" field if the given value is not nil. +func (iu *ImageUpdate) SetNillableURLPath(s *string) *ImageUpdate { + if s != nil { + iu.SetURLPath(*s) + } + return iu +} + // AddUserProfilePicIDs adds the "user_profile_pic" edge to the User entity by IDs. func (iu *ImageUpdate) AddUserProfilePicIDs(ids ...int) *ImageUpdate { iu.mutation.AddUserProfilePicIDs(ids...) @@ -77,7 +85,7 @@ func (iu *ImageUpdate) RemoveUserProfilePic(u ...*User) *ImageUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (iu *ImageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, ImageMutation](ctx, iu.sqlSave, iu.mutation, iu.hooks) + return withHooks(ctx, iu.sqlSave, iu.mutation, iu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -185,6 +193,14 @@ func (iuo *ImageUpdateOne) SetURLPath(s string) *ImageUpdateOne { return iuo } +// SetNillableURLPath sets the "url_path" field if the given value is not nil. +func (iuo *ImageUpdateOne) SetNillableURLPath(s *string) *ImageUpdateOne { + if s != nil { + iuo.SetURLPath(*s) + } + return iuo +} + // AddUserProfilePicIDs adds the "user_profile_pic" edge to the User entity by IDs. func (iuo *ImageUpdateOne) AddUserProfilePicIDs(ids ...int) *ImageUpdateOne { iuo.mutation.AddUserProfilePicIDs(ids...) @@ -241,7 +257,7 @@ func (iuo *ImageUpdateOne) Select(field string, fields ...string) *ImageUpdateOn // Save executes the query and returns the updated Image entity. func (iuo *ImageUpdateOne) Save(ctx context.Context) (*Image, error) { - return withHooks[*Image, ImageMutation](ctx, iuo.sqlSave, iuo.mutation, iuo.hooks) + return withHooks(ctx, iuo.sqlSave, iuo.mutation, iuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/implicitskippedmessage/where.go b/entproto/internal/entprototest/ent/implicitskippedmessage/where.go index 349e151d8..f382cc67f 100644 --- a/entproto/internal/entprototest/ent/implicitskippedmessage/where.go +++ b/entproto/internal/entprototest/ent/implicitskippedmessage/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.ImplicitSkippedMessage { // And groups predicates with the AND operator between them. func And(predicates ...predicate.ImplicitSkippedMessage) predicate.ImplicitSkippedMessage { - return predicate.ImplicitSkippedMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.ImplicitSkippedMessage(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.ImplicitSkippedMessage) predicate.ImplicitSkippedMessage { - return predicate.ImplicitSkippedMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.ImplicitSkippedMessage(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.ImplicitSkippedMessage) predicate.ImplicitSkippedMessage { - return predicate.ImplicitSkippedMessage(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.ImplicitSkippedMessage(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/implicitskippedmessage_create.go b/entproto/internal/entprototest/ent/implicitskippedmessage_create.go index da6c0f21e..a1f300df7 100644 --- a/entproto/internal/entprototest/ent/implicitskippedmessage_create.go +++ b/entproto/internal/entprototest/ent/implicitskippedmessage_create.go @@ -25,7 +25,7 @@ func (ismc *ImplicitSkippedMessageCreate) Mutation() *ImplicitSkippedMessageMuta // Save creates the ImplicitSkippedMessage in the database. func (ismc *ImplicitSkippedMessageCreate) Save(ctx context.Context) (*ImplicitSkippedMessage, error) { - return withHooks[*ImplicitSkippedMessage, ImplicitSkippedMessageMutation](ctx, ismc.sqlSave, ismc.mutation, ismc.hooks) + return withHooks(ctx, ismc.sqlSave, ismc.mutation, ismc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (ismc *ImplicitSkippedMessageCreate) createSpec() (*ImplicitSkippedMessage, // ImplicitSkippedMessageCreateBulk is the builder for creating many ImplicitSkippedMessage entities in bulk. type ImplicitSkippedMessageCreateBulk struct { config + err error builders []*ImplicitSkippedMessageCreate } // Save creates the ImplicitSkippedMessage entities in the database. func (ismcb *ImplicitSkippedMessageCreateBulk) Save(ctx context.Context) ([]*ImplicitSkippedMessage, error) { + if ismcb.err != nil { + return nil, ismcb.err + } specs := make([]*sqlgraph.CreateSpec, len(ismcb.builders)) nodes := make([]*ImplicitSkippedMessage, len(ismcb.builders)) mutators := make([]Mutator, len(ismcb.builders)) diff --git a/entproto/internal/entprototest/ent/implicitskippedmessage_delete.go b/entproto/internal/entprototest/ent/implicitskippedmessage_delete.go index 3bd13344f..c87764c95 100644 --- a/entproto/internal/entprototest/ent/implicitskippedmessage_delete.go +++ b/entproto/internal/entprototest/ent/implicitskippedmessage_delete.go @@ -27,7 +27,7 @@ func (ismd *ImplicitSkippedMessageDelete) Where(ps ...predicate.ImplicitSkippedM // Exec executes the deletion query and returns how many vertices were deleted. func (ismd *ImplicitSkippedMessageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, ImplicitSkippedMessageMutation](ctx, ismd.sqlExec, ismd.mutation, ismd.hooks) + return withHooks(ctx, ismd.sqlExec, ismd.mutation, ismd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/implicitskippedmessage_update.go b/entproto/internal/entprototest/ent/implicitskippedmessage_update.go index 61195ebf3..ddfbf73c7 100644 --- a/entproto/internal/entprototest/ent/implicitskippedmessage_update.go +++ b/entproto/internal/entprototest/ent/implicitskippedmessage_update.go @@ -34,7 +34,7 @@ func (ismu *ImplicitSkippedMessageUpdate) Mutation() *ImplicitSkippedMessageMuta // Save executes the query and returns the number of nodes affected by the update operation. func (ismu *ImplicitSkippedMessageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, ImplicitSkippedMessageMutation](ctx, ismu.sqlSave, ismu.mutation, ismu.hooks) + return withHooks(ctx, ismu.sqlSave, ismu.mutation, ismu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (ismuo *ImplicitSkippedMessageUpdateOne) Select(field string, fields ...str // Save executes the query and returns the updated ImplicitSkippedMessage entity. func (ismuo *ImplicitSkippedMessageUpdateOne) Save(ctx context.Context) (*ImplicitSkippedMessage, error) { - return withHooks[*ImplicitSkippedMessage, ImplicitSkippedMessageMutation](ctx, ismuo.sqlSave, ismuo.mutation, ismuo.hooks) + return withHooks(ctx, ismuo.sqlSave, ismuo.mutation, ismuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/invalidfieldmessage/where.go b/entproto/internal/entprototest/ent/invalidfieldmessage/where.go index b5d840b73..980fed194 100644 --- a/entproto/internal/entprototest/ent/invalidfieldmessage/where.go +++ b/entproto/internal/entprototest/ent/invalidfieldmessage/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.InvalidFieldMessage { // And groups predicates with the AND operator between them. func And(predicates ...predicate.InvalidFieldMessage) predicate.InvalidFieldMessage { - return predicate.InvalidFieldMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.InvalidFieldMessage(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.InvalidFieldMessage) predicate.InvalidFieldMessage { - return predicate.InvalidFieldMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.InvalidFieldMessage(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.InvalidFieldMessage) predicate.InvalidFieldMessage { - return predicate.InvalidFieldMessage(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.InvalidFieldMessage(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/invalidfieldmessage_create.go b/entproto/internal/entprototest/ent/invalidfieldmessage_create.go index 2413cb51b..cd111e031 100644 --- a/entproto/internal/entprototest/ent/invalidfieldmessage_create.go +++ b/entproto/internal/entprototest/ent/invalidfieldmessage_create.go @@ -33,7 +33,7 @@ func (ifmc *InvalidFieldMessageCreate) Mutation() *InvalidFieldMessageMutation { // Save creates the InvalidFieldMessage in the database. func (ifmc *InvalidFieldMessageCreate) Save(ctx context.Context) (*InvalidFieldMessage, error) { - return withHooks[*InvalidFieldMessage, InvalidFieldMessageMutation](ctx, ifmc.sqlSave, ifmc.mutation, ifmc.hooks) + return withHooks(ctx, ifmc.sqlSave, ifmc.mutation, ifmc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -99,11 +99,15 @@ func (ifmc *InvalidFieldMessageCreate) createSpec() (*InvalidFieldMessage, *sqlg // InvalidFieldMessageCreateBulk is the builder for creating many InvalidFieldMessage entities in bulk. type InvalidFieldMessageCreateBulk struct { config + err error builders []*InvalidFieldMessageCreate } // Save creates the InvalidFieldMessage entities in the database. func (ifmcb *InvalidFieldMessageCreateBulk) Save(ctx context.Context) ([]*InvalidFieldMessage, error) { + if ifmcb.err != nil { + return nil, ifmcb.err + } specs := make([]*sqlgraph.CreateSpec, len(ifmcb.builders)) nodes := make([]*InvalidFieldMessage, len(ifmcb.builders)) mutators := make([]Mutator, len(ifmcb.builders)) diff --git a/entproto/internal/entprototest/ent/invalidfieldmessage_delete.go b/entproto/internal/entprototest/ent/invalidfieldmessage_delete.go index dc2dd483a..60d6e579d 100644 --- a/entproto/internal/entprototest/ent/invalidfieldmessage_delete.go +++ b/entproto/internal/entprototest/ent/invalidfieldmessage_delete.go @@ -27,7 +27,7 @@ func (ifmd *InvalidFieldMessageDelete) Where(ps ...predicate.InvalidFieldMessage // Exec executes the deletion query and returns how many vertices were deleted. func (ifmd *InvalidFieldMessageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, InvalidFieldMessageMutation](ctx, ifmd.sqlExec, ifmd.mutation, ifmd.hooks) + return withHooks(ctx, ifmd.sqlExec, ifmd.mutation, ifmd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/invalidfieldmessage_update.go b/entproto/internal/entprototest/ent/invalidfieldmessage_update.go index c11c5bf3e..6ed644885 100644 --- a/entproto/internal/entprototest/ent/invalidfieldmessage_update.go +++ b/entproto/internal/entprototest/ent/invalidfieldmessage_update.go @@ -41,7 +41,7 @@ func (ifmu *InvalidFieldMessageUpdate) Mutation() *InvalidFieldMessageMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (ifmu *InvalidFieldMessageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, InvalidFieldMessageMutation](ctx, ifmu.sqlSave, ifmu.mutation, ifmu.hooks) + return withHooks(ctx, ifmu.sqlSave, ifmu.mutation, ifmu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -124,7 +124,7 @@ func (ifmuo *InvalidFieldMessageUpdateOne) Select(field string, fields ...string // Save executes the query and returns the updated InvalidFieldMessage entity. func (ifmuo *InvalidFieldMessageUpdateOne) Save(ctx context.Context) (*InvalidFieldMessage, error) { - return withHooks[*InvalidFieldMessage, InvalidFieldMessageMutation](ctx, ifmuo.sqlSave, ifmuo.mutation, ifmuo.hooks) + return withHooks(ctx, ifmuo.sqlSave, ifmuo.mutation, ifmuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithenum/where.go b/entproto/internal/entprototest/ent/messagewithenum/where.go index 4b2c7587c..ea8f10592 100644 --- a/entproto/internal/entprototest/ent/messagewithenum/where.go +++ b/entproto/internal/entprototest/ent/messagewithenum/where.go @@ -114,32 +114,15 @@ func EnumWithSpecialCharactersNotIn(vs ...EnumWithSpecialCharacters) predicate.M // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithEnum) predicate.MessageWithEnum { - return predicate.MessageWithEnum(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithEnum(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MessageWithEnum) predicate.MessageWithEnum { - return predicate.MessageWithEnum(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithEnum(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MessageWithEnum) predicate.MessageWithEnum { - return predicate.MessageWithEnum(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MessageWithEnum(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/messagewithenum_create.go b/entproto/internal/entprototest/ent/messagewithenum_create.go index bf6b41745..75a39ab5a 100644 --- a/entproto/internal/entprototest/ent/messagewithenum_create.go +++ b/entproto/internal/entprototest/ent/messagewithenum_create.go @@ -53,7 +53,7 @@ func (mwec *MessageWithEnumCreate) Mutation() *MessageWithEnumMutation { // Save creates the MessageWithEnum in the database. func (mwec *MessageWithEnumCreate) Save(ctx context.Context) (*MessageWithEnum, error) { mwec.defaults() - return withHooks[*MessageWithEnum, MessageWithEnumMutation](ctx, mwec.sqlSave, mwec.mutation, mwec.hooks) + return withHooks(ctx, mwec.sqlSave, mwec.mutation, mwec.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -156,11 +156,15 @@ func (mwec *MessageWithEnumCreate) createSpec() (*MessageWithEnum, *sqlgraph.Cre // MessageWithEnumCreateBulk is the builder for creating many MessageWithEnum entities in bulk. type MessageWithEnumCreateBulk struct { config + err error builders []*MessageWithEnumCreate } // Save creates the MessageWithEnum entities in the database. func (mwecb *MessageWithEnumCreateBulk) Save(ctx context.Context) ([]*MessageWithEnum, error) { + if mwecb.err != nil { + return nil, mwecb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwecb.builders)) nodes := make([]*MessageWithEnum, len(mwecb.builders)) mutators := make([]Mutator, len(mwecb.builders)) diff --git a/entproto/internal/entprototest/ent/messagewithenum_delete.go b/entproto/internal/entprototest/ent/messagewithenum_delete.go index 78b9625d3..e05ddda25 100644 --- a/entproto/internal/entprototest/ent/messagewithenum_delete.go +++ b/entproto/internal/entprototest/ent/messagewithenum_delete.go @@ -27,7 +27,7 @@ func (mwed *MessageWithEnumDelete) Where(ps ...predicate.MessageWithEnum) *Messa // Exec executes the deletion query and returns how many vertices were deleted. func (mwed *MessageWithEnumDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageWithEnumMutation](ctx, mwed.sqlExec, mwed.mutation, mwed.hooks) + return withHooks(ctx, mwed.sqlExec, mwed.mutation, mwed.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithenum_update.go b/entproto/internal/entprototest/ent/messagewithenum_update.go index fbc918c72..d7dcf7e69 100644 --- a/entproto/internal/entprototest/ent/messagewithenum_update.go +++ b/entproto/internal/entprototest/ent/messagewithenum_update.go @@ -47,12 +47,28 @@ func (mweu *MessageWithEnumUpdate) SetEnumWithoutDefault(mwd messagewithenum.Enu return mweu } +// SetNillableEnumWithoutDefault sets the "enum_without_default" field if the given value is not nil. +func (mweu *MessageWithEnumUpdate) SetNillableEnumWithoutDefault(mwd *messagewithenum.EnumWithoutDefault) *MessageWithEnumUpdate { + if mwd != nil { + mweu.SetEnumWithoutDefault(*mwd) + } + return mweu +} + // SetEnumWithSpecialCharacters sets the "enum_with_special_characters" field. func (mweu *MessageWithEnumUpdate) SetEnumWithSpecialCharacters(mwsc messagewithenum.EnumWithSpecialCharacters) *MessageWithEnumUpdate { mweu.mutation.SetEnumWithSpecialCharacters(mwsc) return mweu } +// SetNillableEnumWithSpecialCharacters sets the "enum_with_special_characters" field if the given value is not nil. +func (mweu *MessageWithEnumUpdate) SetNillableEnumWithSpecialCharacters(mwsc *messagewithenum.EnumWithSpecialCharacters) *MessageWithEnumUpdate { + if mwsc != nil { + mweu.SetEnumWithSpecialCharacters(*mwsc) + } + return mweu +} + // Mutation returns the MessageWithEnumMutation object of the builder. func (mweu *MessageWithEnumUpdate) Mutation() *MessageWithEnumMutation { return mweu.mutation @@ -60,7 +76,7 @@ func (mweu *MessageWithEnumUpdate) Mutation() *MessageWithEnumMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (mweu *MessageWithEnumUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageWithEnumMutation](ctx, mweu.sqlSave, mweu.mutation, mweu.hooks) + return withHooks(ctx, mweu.sqlSave, mweu.mutation, mweu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -166,12 +182,28 @@ func (mweuo *MessageWithEnumUpdateOne) SetEnumWithoutDefault(mwd messagewithenum return mweuo } +// SetNillableEnumWithoutDefault sets the "enum_without_default" field if the given value is not nil. +func (mweuo *MessageWithEnumUpdateOne) SetNillableEnumWithoutDefault(mwd *messagewithenum.EnumWithoutDefault) *MessageWithEnumUpdateOne { + if mwd != nil { + mweuo.SetEnumWithoutDefault(*mwd) + } + return mweuo +} + // SetEnumWithSpecialCharacters sets the "enum_with_special_characters" field. func (mweuo *MessageWithEnumUpdateOne) SetEnumWithSpecialCharacters(mwsc messagewithenum.EnumWithSpecialCharacters) *MessageWithEnumUpdateOne { mweuo.mutation.SetEnumWithSpecialCharacters(mwsc) return mweuo } +// SetNillableEnumWithSpecialCharacters sets the "enum_with_special_characters" field if the given value is not nil. +func (mweuo *MessageWithEnumUpdateOne) SetNillableEnumWithSpecialCharacters(mwsc *messagewithenum.EnumWithSpecialCharacters) *MessageWithEnumUpdateOne { + if mwsc != nil { + mweuo.SetEnumWithSpecialCharacters(*mwsc) + } + return mweuo +} + // Mutation returns the MessageWithEnumMutation object of the builder. func (mweuo *MessageWithEnumUpdateOne) Mutation() *MessageWithEnumMutation { return mweuo.mutation @@ -192,7 +224,7 @@ func (mweuo *MessageWithEnumUpdateOne) Select(field string, fields ...string) *M // Save executes the query and returns the updated MessageWithEnum entity. func (mweuo *MessageWithEnumUpdateOne) Save(ctx context.Context) (*MessageWithEnum, error) { - return withHooks[*MessageWithEnum, MessageWithEnumMutation](ctx, mweuo.sqlSave, mweuo.mutation, mweuo.hooks) + return withHooks(ctx, mweuo.sqlSave, mweuo.mutation, mweuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithfieldone/where.go b/entproto/internal/entprototest/ent/messagewithfieldone/where.go index b0deeccbe..7d09b855b 100644 --- a/entproto/internal/entprototest/ent/messagewithfieldone/where.go +++ b/entproto/internal/entprototest/ent/messagewithfieldone/where.go @@ -99,32 +99,15 @@ func FieldOneLTE(v int32) predicate.MessageWithFieldOne { // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithFieldOne) predicate.MessageWithFieldOne { - return predicate.MessageWithFieldOne(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithFieldOne(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MessageWithFieldOne) predicate.MessageWithFieldOne { - return predicate.MessageWithFieldOne(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithFieldOne(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MessageWithFieldOne) predicate.MessageWithFieldOne { - return predicate.MessageWithFieldOne(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MessageWithFieldOne(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/messagewithfieldone_create.go b/entproto/internal/entprototest/ent/messagewithfieldone_create.go index a117b55e9..d7fa512b2 100644 --- a/entproto/internal/entprototest/ent/messagewithfieldone_create.go +++ b/entproto/internal/entprototest/ent/messagewithfieldone_create.go @@ -32,7 +32,7 @@ func (mwfoc *MessageWithFieldOneCreate) Mutation() *MessageWithFieldOneMutation // Save creates the MessageWithFieldOne in the database. func (mwfoc *MessageWithFieldOneCreate) Save(ctx context.Context) (*MessageWithFieldOne, error) { - return withHooks[*MessageWithFieldOne, MessageWithFieldOneMutation](ctx, mwfoc.sqlSave, mwfoc.mutation, mwfoc.hooks) + return withHooks(ctx, mwfoc.sqlSave, mwfoc.mutation, mwfoc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -98,11 +98,15 @@ func (mwfoc *MessageWithFieldOneCreate) createSpec() (*MessageWithFieldOne, *sql // MessageWithFieldOneCreateBulk is the builder for creating many MessageWithFieldOne entities in bulk. type MessageWithFieldOneCreateBulk struct { config + err error builders []*MessageWithFieldOneCreate } // Save creates the MessageWithFieldOne entities in the database. func (mwfocb *MessageWithFieldOneCreateBulk) Save(ctx context.Context) ([]*MessageWithFieldOne, error) { + if mwfocb.err != nil { + return nil, mwfocb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwfocb.builders)) nodes := make([]*MessageWithFieldOne, len(mwfocb.builders)) mutators := make([]Mutator, len(mwfocb.builders)) diff --git a/entproto/internal/entprototest/ent/messagewithfieldone_delete.go b/entproto/internal/entprototest/ent/messagewithfieldone_delete.go index 423a9b29e..ba9815cc5 100644 --- a/entproto/internal/entprototest/ent/messagewithfieldone_delete.go +++ b/entproto/internal/entprototest/ent/messagewithfieldone_delete.go @@ -27,7 +27,7 @@ func (mwfod *MessageWithFieldOneDelete) Where(ps ...predicate.MessageWithFieldOn // Exec executes the deletion query and returns how many vertices were deleted. func (mwfod *MessageWithFieldOneDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageWithFieldOneMutation](ctx, mwfod.sqlExec, mwfod.mutation, mwfod.hooks) + return withHooks(ctx, mwfod.sqlExec, mwfod.mutation, mwfod.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithfieldone_update.go b/entproto/internal/entprototest/ent/messagewithfieldone_update.go index 4c9a84e31..2cd1e0a13 100644 --- a/entproto/internal/entprototest/ent/messagewithfieldone_update.go +++ b/entproto/internal/entprototest/ent/messagewithfieldone_update.go @@ -34,6 +34,14 @@ func (mwfou *MessageWithFieldOneUpdate) SetFieldOne(i int32) *MessageWithFieldOn return mwfou } +// SetNillableFieldOne sets the "field_one" field if the given value is not nil. +func (mwfou *MessageWithFieldOneUpdate) SetNillableFieldOne(i *int32) *MessageWithFieldOneUpdate { + if i != nil { + mwfou.SetFieldOne(*i) + } + return mwfou +} + // AddFieldOne adds i to the "field_one" field. func (mwfou *MessageWithFieldOneUpdate) AddFieldOne(i int32) *MessageWithFieldOneUpdate { mwfou.mutation.AddFieldOne(i) @@ -47,7 +55,7 @@ func (mwfou *MessageWithFieldOneUpdate) Mutation() *MessageWithFieldOneMutation // Save executes the query and returns the number of nodes affected by the update operation. func (mwfou *MessageWithFieldOneUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageWithFieldOneMutation](ctx, mwfou.sqlSave, mwfou.mutation, mwfou.hooks) + return withHooks(ctx, mwfou.sqlSave, mwfou.mutation, mwfou.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -114,6 +122,14 @@ func (mwfouo *MessageWithFieldOneUpdateOne) SetFieldOne(i int32) *MessageWithFie return mwfouo } +// SetNillableFieldOne sets the "field_one" field if the given value is not nil. +func (mwfouo *MessageWithFieldOneUpdateOne) SetNillableFieldOne(i *int32) *MessageWithFieldOneUpdateOne { + if i != nil { + mwfouo.SetFieldOne(*i) + } + return mwfouo +} + // AddFieldOne adds i to the "field_one" field. func (mwfouo *MessageWithFieldOneUpdateOne) AddFieldOne(i int32) *MessageWithFieldOneUpdateOne { mwfouo.mutation.AddFieldOne(i) @@ -140,7 +156,7 @@ func (mwfouo *MessageWithFieldOneUpdateOne) Select(field string, fields ...strin // Save executes the query and returns the updated MessageWithFieldOne entity. func (mwfouo *MessageWithFieldOneUpdateOne) Save(ctx context.Context) (*MessageWithFieldOne, error) { - return withHooks[*MessageWithFieldOne, MessageWithFieldOneMutation](ctx, mwfouo.sqlSave, mwfouo.mutation, mwfouo.hooks) + return withHooks(ctx, mwfouo.sqlSave, mwfouo.mutation, mwfouo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithid/where.go b/entproto/internal/entprototest/ent/messagewithid/where.go index 94098d42e..22fd3302b 100644 --- a/entproto/internal/entprototest/ent/messagewithid/where.go +++ b/entproto/internal/entprototest/ent/messagewithid/where.go @@ -54,32 +54,15 @@ func IDLTE(id int32) predicate.MessageWithID { // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithID) predicate.MessageWithID { - return predicate.MessageWithID(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithID(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MessageWithID) predicate.MessageWithID { - return predicate.MessageWithID(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithID(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MessageWithID) predicate.MessageWithID { - return predicate.MessageWithID(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MessageWithID(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/messagewithid_create.go b/entproto/internal/entprototest/ent/messagewithid_create.go index f628c84db..4c172cf9a 100644 --- a/entproto/internal/entprototest/ent/messagewithid_create.go +++ b/entproto/internal/entprototest/ent/messagewithid_create.go @@ -31,7 +31,7 @@ func (mwic *MessageWithIDCreate) Mutation() *MessageWithIDMutation { // Save creates the MessageWithID in the database. func (mwic *MessageWithIDCreate) Save(ctx context.Context) (*MessageWithID, error) { - return withHooks[*MessageWithID, MessageWithIDMutation](ctx, mwic.sqlSave, mwic.mutation, mwic.hooks) + return withHooks(ctx, mwic.sqlSave, mwic.mutation, mwic.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -96,11 +96,15 @@ func (mwic *MessageWithIDCreate) createSpec() (*MessageWithID, *sqlgraph.CreateS // MessageWithIDCreateBulk is the builder for creating many MessageWithID entities in bulk. type MessageWithIDCreateBulk struct { config + err error builders []*MessageWithIDCreate } // Save creates the MessageWithID entities in the database. func (mwicb *MessageWithIDCreateBulk) Save(ctx context.Context) ([]*MessageWithID, error) { + if mwicb.err != nil { + return nil, mwicb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwicb.builders)) nodes := make([]*MessageWithID, len(mwicb.builders)) mutators := make([]Mutator, len(mwicb.builders)) diff --git a/entproto/internal/entprototest/ent/messagewithid_delete.go b/entproto/internal/entprototest/ent/messagewithid_delete.go index c44a482de..1bb3d0503 100644 --- a/entproto/internal/entprototest/ent/messagewithid_delete.go +++ b/entproto/internal/entprototest/ent/messagewithid_delete.go @@ -27,7 +27,7 @@ func (mwid *MessageWithIDDelete) Where(ps ...predicate.MessageWithID) *MessageWi // Exec executes the deletion query and returns how many vertices were deleted. func (mwid *MessageWithIDDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageWithIDMutation](ctx, mwid.sqlExec, mwid.mutation, mwid.hooks) + return withHooks(ctx, mwid.sqlExec, mwid.mutation, mwid.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithid_update.go b/entproto/internal/entprototest/ent/messagewithid_update.go index 2bcf60441..cd3076b9b 100644 --- a/entproto/internal/entprototest/ent/messagewithid_update.go +++ b/entproto/internal/entprototest/ent/messagewithid_update.go @@ -34,7 +34,7 @@ func (mwiu *MessageWithIDUpdate) Mutation() *MessageWithIDMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (mwiu *MessageWithIDUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageWithIDMutation](ctx, mwiu.sqlSave, mwiu.mutation, mwiu.hooks) + return withHooks(ctx, mwiu.sqlSave, mwiu.mutation, mwiu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (mwiuo *MessageWithIDUpdateOne) Select(field string, fields ...string) *Mes // Save executes the query and returns the updated MessageWithID entity. func (mwiuo *MessageWithIDUpdateOne) Save(ctx context.Context) (*MessageWithID, error) { - return withHooks[*MessageWithID, MessageWithIDMutation](ctx, mwiuo.sqlSave, mwiuo.mutation, mwiuo.hooks) + return withHooks(ctx, mwiuo.sqlSave, mwiuo.mutation, mwiuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithints/where.go b/entproto/internal/entprototest/ent/messagewithints/where.go index 7a25afa21..a1fde57d3 100644 --- a/entproto/internal/entprototest/ent/messagewithints/where.go +++ b/entproto/internal/entprototest/ent/messagewithints/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.MessageWithInts { // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithInts) predicate.MessageWithInts { - return predicate.MessageWithInts(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithInts(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MessageWithInts) predicate.MessageWithInts { - return predicate.MessageWithInts(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithInts(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MessageWithInts) predicate.MessageWithInts { - return predicate.MessageWithInts(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MessageWithInts(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/messagewithints_create.go b/entproto/internal/entprototest/ent/messagewithints_create.go index 5c4bb5b4e..ca3b56e7e 100644 --- a/entproto/internal/entprototest/ent/messagewithints_create.go +++ b/entproto/internal/entprototest/ent/messagewithints_create.go @@ -50,7 +50,7 @@ func (mwic *MessageWithIntsCreate) Mutation() *MessageWithIntsMutation { // Save creates the MessageWithInts in the database. func (mwic *MessageWithIntsCreate) Save(ctx context.Context) (*MessageWithInts, error) { - return withHooks[*MessageWithInts, MessageWithIntsMutation](ctx, mwic.sqlSave, mwic.mutation, mwic.hooks) + return withHooks(ctx, mwic.sqlSave, mwic.mutation, mwic.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -137,11 +137,15 @@ func (mwic *MessageWithIntsCreate) createSpec() (*MessageWithInts, *sqlgraph.Cre // MessageWithIntsCreateBulk is the builder for creating many MessageWithInts entities in bulk. type MessageWithIntsCreateBulk struct { config + err error builders []*MessageWithIntsCreate } // Save creates the MessageWithInts entities in the database. func (mwicb *MessageWithIntsCreateBulk) Save(ctx context.Context) ([]*MessageWithInts, error) { + if mwicb.err != nil { + return nil, mwicb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwicb.builders)) nodes := make([]*MessageWithInts, len(mwicb.builders)) mutators := make([]Mutator, len(mwicb.builders)) diff --git a/entproto/internal/entprototest/ent/messagewithints_delete.go b/entproto/internal/entprototest/ent/messagewithints_delete.go index b39739900..f3712eb51 100644 --- a/entproto/internal/entprototest/ent/messagewithints_delete.go +++ b/entproto/internal/entprototest/ent/messagewithints_delete.go @@ -27,7 +27,7 @@ func (mwid *MessageWithIntsDelete) Where(ps ...predicate.MessageWithInts) *Messa // Exec executes the deletion query and returns how many vertices were deleted. func (mwid *MessageWithIntsDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageWithIntsMutation](ctx, mwid.sqlExec, mwid.mutation, mwid.hooks) + return withHooks(ctx, mwid.sqlExec, mwid.mutation, mwid.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithints_update.go b/entproto/internal/entprototest/ent/messagewithints_update.go index e636a9d04..1342956cd 100644 --- a/entproto/internal/entprototest/ent/messagewithints_update.go +++ b/entproto/internal/entprototest/ent/messagewithints_update.go @@ -83,7 +83,7 @@ func (mwiu *MessageWithIntsUpdate) Mutation() *MessageWithIntsMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (mwiu *MessageWithIntsUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageWithIntsMutation](ctx, mwiu.sqlSave, mwiu.mutation, mwiu.hooks) + return withHooks(ctx, mwiu.sqlSave, mwiu.mutation, mwiu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -237,7 +237,7 @@ func (mwiuo *MessageWithIntsUpdateOne) Select(field string, fields ...string) *M // Save executes the query and returns the updated MessageWithInts entity. func (mwiuo *MessageWithIntsUpdateOne) Save(ctx context.Context) (*MessageWithInts, error) { - return withHooks[*MessageWithInts, MessageWithIntsMutation](ctx, mwiuo.sqlSave, mwiuo.mutation, mwiuo.hooks) + return withHooks(ctx, mwiuo.sqlSave, mwiuo.mutation, mwiuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithoptionals/where.go b/entproto/internal/entprototest/ent/messagewithoptionals/where.go index f60bd10ea..06bc6308c 100644 --- a/entproto/internal/entprototest/ent/messagewithoptionals/where.go +++ b/entproto/internal/entprototest/ent/messagewithoptionals/where.go @@ -492,32 +492,15 @@ func TimeOptionalNotNil() predicate.MessageWithOptionals { // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithOptionals) predicate.MessageWithOptionals { - return predicate.MessageWithOptionals(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithOptionals(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MessageWithOptionals) predicate.MessageWithOptionals { - return predicate.MessageWithOptionals(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithOptionals(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MessageWithOptionals) predicate.MessageWithOptionals { - return predicate.MessageWithOptionals(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MessageWithOptionals(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/messagewithoptionals_create.go b/entproto/internal/entprototest/ent/messagewithoptionals_create.go index acb80a74a..95aa60c2b 100644 --- a/entproto/internal/entprototest/ent/messagewithoptionals_create.go +++ b/entproto/internal/entprototest/ent/messagewithoptionals_create.go @@ -131,7 +131,7 @@ func (mwoc *MessageWithOptionalsCreate) Mutation() *MessageWithOptionalsMutation // Save creates the MessageWithOptionals in the database. func (mwoc *MessageWithOptionalsCreate) Save(ctx context.Context) (*MessageWithOptionals, error) { - return withHooks[*MessageWithOptionals, MessageWithOptionalsMutation](ctx, mwoc.sqlSave, mwoc.mutation, mwoc.hooks) + return withHooks(ctx, mwoc.sqlSave, mwoc.mutation, mwoc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -222,11 +222,15 @@ func (mwoc *MessageWithOptionalsCreate) createSpec() (*MessageWithOptionals, *sq // MessageWithOptionalsCreateBulk is the builder for creating many MessageWithOptionals entities in bulk. type MessageWithOptionalsCreateBulk struct { config + err error builders []*MessageWithOptionalsCreate } // Save creates the MessageWithOptionals entities in the database. func (mwocb *MessageWithOptionalsCreateBulk) Save(ctx context.Context) ([]*MessageWithOptionals, error) { + if mwocb.err != nil { + return nil, mwocb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwocb.builders)) nodes := make([]*MessageWithOptionals, len(mwocb.builders)) mutators := make([]Mutator, len(mwocb.builders)) diff --git a/entproto/internal/entprototest/ent/messagewithoptionals_delete.go b/entproto/internal/entprototest/ent/messagewithoptionals_delete.go index 0e1243f96..910032090 100644 --- a/entproto/internal/entprototest/ent/messagewithoptionals_delete.go +++ b/entproto/internal/entprototest/ent/messagewithoptionals_delete.go @@ -27,7 +27,7 @@ func (mwod *MessageWithOptionalsDelete) Where(ps ...predicate.MessageWithOptiona // Exec executes the deletion query and returns how many vertices were deleted. func (mwod *MessageWithOptionalsDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageWithOptionalsMutation](ctx, mwod.sqlExec, mwod.mutation, mwod.hooks) + return withHooks(ctx, mwod.sqlExec, mwod.mutation, mwod.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithoptionals_update.go b/entproto/internal/entprototest/ent/messagewithoptionals_update.go index 834acab35..582d06102 100644 --- a/entproto/internal/entprototest/ent/messagewithoptionals_update.go +++ b/entproto/internal/entprototest/ent/messagewithoptionals_update.go @@ -209,7 +209,7 @@ func (mwou *MessageWithOptionalsUpdate) Mutation() *MessageWithOptionalsMutation // Save executes the query and returns the number of nodes affected by the update operation. func (mwou *MessageWithOptionalsUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageWithOptionalsMutation](ctx, mwou.sqlSave, mwou.mutation, mwou.hooks) + return withHooks(ctx, mwou.sqlSave, mwou.mutation, mwou.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -513,7 +513,7 @@ func (mwouo *MessageWithOptionalsUpdateOne) Select(field string, fields ...strin // Save executes the query and returns the updated MessageWithOptionals entity. func (mwouo *MessageWithOptionalsUpdateOne) Save(ctx context.Context) (*MessageWithOptionals, error) { - return withHooks[*MessageWithOptionals, MessageWithOptionalsMutation](ctx, mwouo.sqlSave, mwouo.mutation, mwouo.hooks) + return withHooks(ctx, mwouo.sqlSave, mwouo.mutation, mwouo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithpackagename/where.go b/entproto/internal/entprototest/ent/messagewithpackagename/where.go index 57c409aae..bf8a0019a 100644 --- a/entproto/internal/entprototest/ent/messagewithpackagename/where.go +++ b/entproto/internal/entprototest/ent/messagewithpackagename/where.go @@ -124,32 +124,15 @@ func NameContainsFold(v string) predicate.MessageWithPackageName { // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithPackageName) predicate.MessageWithPackageName { - return predicate.MessageWithPackageName(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithPackageName(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MessageWithPackageName) predicate.MessageWithPackageName { - return predicate.MessageWithPackageName(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithPackageName(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MessageWithPackageName) predicate.MessageWithPackageName { - return predicate.MessageWithPackageName(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MessageWithPackageName(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/messagewithpackagename_create.go b/entproto/internal/entprototest/ent/messagewithpackagename_create.go index 2d4242f7e..c6b927882 100644 --- a/entproto/internal/entprototest/ent/messagewithpackagename_create.go +++ b/entproto/internal/entprototest/ent/messagewithpackagename_create.go @@ -32,7 +32,7 @@ func (mwpnc *MessageWithPackageNameCreate) Mutation() *MessageWithPackageNameMut // Save creates the MessageWithPackageName in the database. func (mwpnc *MessageWithPackageNameCreate) Save(ctx context.Context) (*MessageWithPackageName, error) { - return withHooks[*MessageWithPackageName, MessageWithPackageNameMutation](ctx, mwpnc.sqlSave, mwpnc.mutation, mwpnc.hooks) + return withHooks(ctx, mwpnc.sqlSave, mwpnc.mutation, mwpnc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -98,11 +98,15 @@ func (mwpnc *MessageWithPackageNameCreate) createSpec() (*MessageWithPackageName // MessageWithPackageNameCreateBulk is the builder for creating many MessageWithPackageName entities in bulk. type MessageWithPackageNameCreateBulk struct { config + err error builders []*MessageWithPackageNameCreate } // Save creates the MessageWithPackageName entities in the database. func (mwpncb *MessageWithPackageNameCreateBulk) Save(ctx context.Context) ([]*MessageWithPackageName, error) { + if mwpncb.err != nil { + return nil, mwpncb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwpncb.builders)) nodes := make([]*MessageWithPackageName, len(mwpncb.builders)) mutators := make([]Mutator, len(mwpncb.builders)) diff --git a/entproto/internal/entprototest/ent/messagewithpackagename_delete.go b/entproto/internal/entprototest/ent/messagewithpackagename_delete.go index a32d1119c..2a2c2e0d1 100644 --- a/entproto/internal/entprototest/ent/messagewithpackagename_delete.go +++ b/entproto/internal/entprototest/ent/messagewithpackagename_delete.go @@ -27,7 +27,7 @@ func (mwpnd *MessageWithPackageNameDelete) Where(ps ...predicate.MessageWithPack // Exec executes the deletion query and returns how many vertices were deleted. func (mwpnd *MessageWithPackageNameDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageWithPackageNameMutation](ctx, mwpnd.sqlExec, mwpnd.mutation, mwpnd.hooks) + return withHooks(ctx, mwpnd.sqlExec, mwpnd.mutation, mwpnd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithpackagename_update.go b/entproto/internal/entprototest/ent/messagewithpackagename_update.go index f2dc00e0c..e9bcd47ed 100644 --- a/entproto/internal/entprototest/ent/messagewithpackagename_update.go +++ b/entproto/internal/entprototest/ent/messagewithpackagename_update.go @@ -33,6 +33,14 @@ func (mwpnu *MessageWithPackageNameUpdate) SetName(s string) *MessageWithPackage return mwpnu } +// SetNillableName sets the "name" field if the given value is not nil. +func (mwpnu *MessageWithPackageNameUpdate) SetNillableName(s *string) *MessageWithPackageNameUpdate { + if s != nil { + mwpnu.SetName(*s) + } + return mwpnu +} + // Mutation returns the MessageWithPackageNameMutation object of the builder. func (mwpnu *MessageWithPackageNameUpdate) Mutation() *MessageWithPackageNameMutation { return mwpnu.mutation @@ -40,7 +48,7 @@ func (mwpnu *MessageWithPackageNameUpdate) Mutation() *MessageWithPackageNameMut // Save executes the query and returns the number of nodes affected by the update operation. func (mwpnu *MessageWithPackageNameUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageWithPackageNameMutation](ctx, mwpnu.sqlSave, mwpnu.mutation, mwpnu.hooks) + return withHooks(ctx, mwpnu.sqlSave, mwpnu.mutation, mwpnu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -103,6 +111,14 @@ func (mwpnuo *MessageWithPackageNameUpdateOne) SetName(s string) *MessageWithPac return mwpnuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (mwpnuo *MessageWithPackageNameUpdateOne) SetNillableName(s *string) *MessageWithPackageNameUpdateOne { + if s != nil { + mwpnuo.SetName(*s) + } + return mwpnuo +} + // Mutation returns the MessageWithPackageNameMutation object of the builder. func (mwpnuo *MessageWithPackageNameUpdateOne) Mutation() *MessageWithPackageNameMutation { return mwpnuo.mutation @@ -123,7 +139,7 @@ func (mwpnuo *MessageWithPackageNameUpdateOne) Select(field string, fields ...st // Save executes the query and returns the updated MessageWithPackageName entity. func (mwpnuo *MessageWithPackageNameUpdateOne) Save(ctx context.Context) (*MessageWithPackageName, error) { - return withHooks[*MessageWithPackageName, MessageWithPackageNameMutation](ctx, mwpnuo.sqlSave, mwpnuo.mutation, mwpnuo.hooks) + return withHooks(ctx, mwpnuo.sqlSave, mwpnuo.mutation, mwpnuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithstrings/where.go b/entproto/internal/entprototest/ent/messagewithstrings/where.go index cc9459360..fc4b392b9 100644 --- a/entproto/internal/entprototest/ent/messagewithstrings/where.go +++ b/entproto/internal/entprototest/ent/messagewithstrings/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.MessageWithStrings { // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithStrings) predicate.MessageWithStrings { - return predicate.MessageWithStrings(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithStrings(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MessageWithStrings) predicate.MessageWithStrings { - return predicate.MessageWithStrings(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MessageWithStrings(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MessageWithStrings) predicate.MessageWithStrings { - return predicate.MessageWithStrings(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MessageWithStrings(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/messagewithstrings_create.go b/entproto/internal/entprototest/ent/messagewithstrings_create.go index 55478d063..8610c912b 100644 --- a/entproto/internal/entprototest/ent/messagewithstrings_create.go +++ b/entproto/internal/entprototest/ent/messagewithstrings_create.go @@ -32,7 +32,7 @@ func (mwsc *MessageWithStringsCreate) Mutation() *MessageWithStringsMutation { // Save creates the MessageWithStrings in the database. func (mwsc *MessageWithStringsCreate) Save(ctx context.Context) (*MessageWithStrings, error) { - return withHooks[*MessageWithStrings, MessageWithStringsMutation](ctx, mwsc.sqlSave, mwsc.mutation, mwsc.hooks) + return withHooks(ctx, mwsc.sqlSave, mwsc.mutation, mwsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -98,11 +98,15 @@ func (mwsc *MessageWithStringsCreate) createSpec() (*MessageWithStrings, *sqlgra // MessageWithStringsCreateBulk is the builder for creating many MessageWithStrings entities in bulk. type MessageWithStringsCreateBulk struct { config + err error builders []*MessageWithStringsCreate } // Save creates the MessageWithStrings entities in the database. func (mwscb *MessageWithStringsCreateBulk) Save(ctx context.Context) ([]*MessageWithStrings, error) { + if mwscb.err != nil { + return nil, mwscb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwscb.builders)) nodes := make([]*MessageWithStrings, len(mwscb.builders)) mutators := make([]Mutator, len(mwscb.builders)) diff --git a/entproto/internal/entprototest/ent/messagewithstrings_delete.go b/entproto/internal/entprototest/ent/messagewithstrings_delete.go index 61b86b3d4..d5c037220 100644 --- a/entproto/internal/entprototest/ent/messagewithstrings_delete.go +++ b/entproto/internal/entprototest/ent/messagewithstrings_delete.go @@ -27,7 +27,7 @@ func (mwsd *MessageWithStringsDelete) Where(ps ...predicate.MessageWithStrings) // Exec executes the deletion query and returns how many vertices were deleted. func (mwsd *MessageWithStringsDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageWithStringsMutation](ctx, mwsd.sqlExec, mwsd.mutation, mwsd.hooks) + return withHooks(ctx, mwsd.sqlExec, mwsd.mutation, mwsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/messagewithstrings_update.go b/entproto/internal/entprototest/ent/messagewithstrings_update.go index 5f4010599..117e631fc 100644 --- a/entproto/internal/entprototest/ent/messagewithstrings_update.go +++ b/entproto/internal/entprototest/ent/messagewithstrings_update.go @@ -47,7 +47,7 @@ func (mwsu *MessageWithStringsUpdate) Mutation() *MessageWithStringsMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (mwsu *MessageWithStringsUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageWithStringsMutation](ctx, mwsu.sqlSave, mwsu.mutation, mwsu.hooks) + return withHooks(ctx, mwsu.sqlSave, mwsu.mutation, mwsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -141,7 +141,7 @@ func (mwsuo *MessageWithStringsUpdateOne) Select(field string, fields ...string) // Save executes the query and returns the updated MessageWithStrings entity. func (mwsuo *MessageWithStringsUpdateOne) Save(ctx context.Context) (*MessageWithStrings, error) { - return withHooks[*MessageWithStrings, MessageWithStringsMutation](ctx, mwsuo.sqlSave, mwsuo.mutation, mwsuo.hooks) + return withHooks(ctx, mwsuo.sqlSave, mwsuo.mutation, mwsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/nobackref/where.go b/entproto/internal/entprototest/ent/nobackref/where.go index 8b6d64d5b..ad160b959 100644 --- a/entproto/internal/entprototest/ent/nobackref/where.go +++ b/entproto/internal/entprototest/ent/nobackref/where.go @@ -78,32 +78,15 @@ func HasImagesWith(preds ...predicate.Image) predicate.NoBackref { // And groups predicates with the AND operator between them. func And(predicates ...predicate.NoBackref) predicate.NoBackref { - return predicate.NoBackref(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.NoBackref(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.NoBackref) predicate.NoBackref { - return predicate.NoBackref(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.NoBackref(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.NoBackref) predicate.NoBackref { - return predicate.NoBackref(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.NoBackref(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/nobackref_create.go b/entproto/internal/entprototest/ent/nobackref_create.go index 3a3e1665d..8357275f6 100644 --- a/entproto/internal/entprototest/ent/nobackref_create.go +++ b/entproto/internal/entprototest/ent/nobackref_create.go @@ -42,7 +42,7 @@ func (nbc *NoBackrefCreate) Mutation() *NoBackrefMutation { // Save creates the NoBackref in the database. func (nbc *NoBackrefCreate) Save(ctx context.Context) (*NoBackref, error) { - return withHooks[*NoBackref, NoBackrefMutation](ctx, nbc.sqlSave, nbc.mutation, nbc.hooks) + return withHooks(ctx, nbc.sqlSave, nbc.mutation, nbc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -117,11 +117,15 @@ func (nbc *NoBackrefCreate) createSpec() (*NoBackref, *sqlgraph.CreateSpec) { // NoBackrefCreateBulk is the builder for creating many NoBackref entities in bulk. type NoBackrefCreateBulk struct { config + err error builders []*NoBackrefCreate } // Save creates the NoBackref entities in the database. func (nbcb *NoBackrefCreateBulk) Save(ctx context.Context) ([]*NoBackref, error) { + if nbcb.err != nil { + return nil, nbcb.err + } specs := make([]*sqlgraph.CreateSpec, len(nbcb.builders)) nodes := make([]*NoBackref, len(nbcb.builders)) mutators := make([]Mutator, len(nbcb.builders)) diff --git a/entproto/internal/entprototest/ent/nobackref_delete.go b/entproto/internal/entprototest/ent/nobackref_delete.go index 11701e7a2..da3019afe 100644 --- a/entproto/internal/entprototest/ent/nobackref_delete.go +++ b/entproto/internal/entprototest/ent/nobackref_delete.go @@ -27,7 +27,7 @@ func (nbd *NoBackrefDelete) Where(ps ...predicate.NoBackref) *NoBackrefDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (nbd *NoBackrefDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, NoBackrefMutation](ctx, nbd.sqlExec, nbd.mutation, nbd.hooks) + return withHooks(ctx, nbd.sqlExec, nbd.mutation, nbd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/nobackref_update.go b/entproto/internal/entprototest/ent/nobackref_update.go index 154fc0a78..b335bd533 100644 --- a/entproto/internal/entprototest/ent/nobackref_update.go +++ b/entproto/internal/entprototest/ent/nobackref_update.go @@ -72,7 +72,7 @@ func (nbu *NoBackrefUpdate) RemoveImages(i ...*Image) *NoBackrefUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (nbu *NoBackrefUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, NoBackrefMutation](ctx, nbu.sqlSave, nbu.mutation, nbu.hooks) + return withHooks(ctx, nbu.sqlSave, nbu.mutation, nbu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -227,7 +227,7 @@ func (nbuo *NoBackrefUpdateOne) Select(field string, fields ...string) *NoBackre // Save executes the query and returns the updated NoBackref entity. func (nbuo *NoBackrefUpdateOne) Save(ctx context.Context) (*NoBackref, error) { - return withHooks[*NoBackref, NoBackrefMutation](ctx, nbuo.sqlSave, nbuo.mutation, nbuo.hooks) + return withHooks(ctx, nbuo.sqlSave, nbuo.mutation, nbuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/onemethodservice/where.go b/entproto/internal/entprototest/ent/onemethodservice/where.go index be5415ff5..e034e972b 100644 --- a/entproto/internal/entprototest/ent/onemethodservice/where.go +++ b/entproto/internal/entprototest/ent/onemethodservice/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.OneMethodService { // And groups predicates with the AND operator between them. func And(predicates ...predicate.OneMethodService) predicate.OneMethodService { - return predicate.OneMethodService(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.OneMethodService(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.OneMethodService) predicate.OneMethodService { - return predicate.OneMethodService(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.OneMethodService(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.OneMethodService) predicate.OneMethodService { - return predicate.OneMethodService(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.OneMethodService(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/onemethodservice_create.go b/entproto/internal/entprototest/ent/onemethodservice_create.go index a2e9889b8..cd31d23b1 100644 --- a/entproto/internal/entprototest/ent/onemethodservice_create.go +++ b/entproto/internal/entprototest/ent/onemethodservice_create.go @@ -25,7 +25,7 @@ func (omsc *OneMethodServiceCreate) Mutation() *OneMethodServiceMutation { // Save creates the OneMethodService in the database. func (omsc *OneMethodServiceCreate) Save(ctx context.Context) (*OneMethodService, error) { - return withHooks[*OneMethodService, OneMethodServiceMutation](ctx, omsc.sqlSave, omsc.mutation, omsc.hooks) + return withHooks(ctx, omsc.sqlSave, omsc.mutation, omsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (omsc *OneMethodServiceCreate) createSpec() (*OneMethodService, *sqlgraph.C // OneMethodServiceCreateBulk is the builder for creating many OneMethodService entities in bulk. type OneMethodServiceCreateBulk struct { config + err error builders []*OneMethodServiceCreate } // Save creates the OneMethodService entities in the database. func (omscb *OneMethodServiceCreateBulk) Save(ctx context.Context) ([]*OneMethodService, error) { + if omscb.err != nil { + return nil, omscb.err + } specs := make([]*sqlgraph.CreateSpec, len(omscb.builders)) nodes := make([]*OneMethodService, len(omscb.builders)) mutators := make([]Mutator, len(omscb.builders)) diff --git a/entproto/internal/entprototest/ent/onemethodservice_delete.go b/entproto/internal/entprototest/ent/onemethodservice_delete.go index 83e6677fd..af09d4ea4 100644 --- a/entproto/internal/entprototest/ent/onemethodservice_delete.go +++ b/entproto/internal/entprototest/ent/onemethodservice_delete.go @@ -27,7 +27,7 @@ func (omsd *OneMethodServiceDelete) Where(ps ...predicate.OneMethodService) *One // Exec executes the deletion query and returns how many vertices were deleted. func (omsd *OneMethodServiceDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, OneMethodServiceMutation](ctx, omsd.sqlExec, omsd.mutation, omsd.hooks) + return withHooks(ctx, omsd.sqlExec, omsd.mutation, omsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/onemethodservice_update.go b/entproto/internal/entprototest/ent/onemethodservice_update.go index 09deeede2..42e109e1b 100644 --- a/entproto/internal/entprototest/ent/onemethodservice_update.go +++ b/entproto/internal/entprototest/ent/onemethodservice_update.go @@ -34,7 +34,7 @@ func (omsu *OneMethodServiceUpdate) Mutation() *OneMethodServiceMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (omsu *OneMethodServiceUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, OneMethodServiceMutation](ctx, omsu.sqlSave, omsu.mutation, omsu.hooks) + return withHooks(ctx, omsu.sqlSave, omsu.mutation, omsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (omsuo *OneMethodServiceUpdateOne) Select(field string, fields ...string) * // Save executes the query and returns the updated OneMethodService entity. func (omsuo *OneMethodServiceUpdateOne) Save(ctx context.Context) (*OneMethodService, error) { - return withHooks[*OneMethodService, OneMethodServiceMutation](ctx, omsuo.sqlSave, omsuo.mutation, omsuo.hooks) + return withHooks(ctx, omsuo.sqlSave, omsuo.mutation, omsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/portal/where.go b/entproto/internal/entprototest/ent/portal/where.go index 9dd498e90..c7e77e112 100644 --- a/entproto/internal/entprototest/ent/portal/where.go +++ b/entproto/internal/entprototest/ent/portal/where.go @@ -218,32 +218,15 @@ func HasCategoryWith(preds ...predicate.Category) predicate.Portal { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Portal) predicate.Portal { - return predicate.Portal(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Portal(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Portal) predicate.Portal { - return predicate.Portal(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Portal(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Portal) predicate.Portal { - return predicate.Portal(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Portal(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/portal_create.go b/entproto/internal/entprototest/ent/portal_create.go index 8c0d75472..c60a697df 100644 --- a/entproto/internal/entprototest/ent/portal_create.go +++ b/entproto/internal/entprototest/ent/portal_create.go @@ -58,7 +58,7 @@ func (pc *PortalCreate) Mutation() *PortalMutation { // Save creates the Portal in the database. func (pc *PortalCreate) Save(ctx context.Context) (*Portal, error) { - return withHooks[*Portal, PortalMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -148,11 +148,15 @@ func (pc *PortalCreate) createSpec() (*Portal, *sqlgraph.CreateSpec) { // PortalCreateBulk is the builder for creating many Portal entities in bulk. type PortalCreateBulk struct { config + err error builders []*PortalCreate } // Save creates the Portal entities in the database. func (pcb *PortalCreateBulk) Save(ctx context.Context) ([]*Portal, error) { + if pcb.err != nil { + return nil, pcb.err + } specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) nodes := make([]*Portal, len(pcb.builders)) mutators := make([]Mutator, len(pcb.builders)) diff --git a/entproto/internal/entprototest/ent/portal_delete.go b/entproto/internal/entprototest/ent/portal_delete.go index e7746711c..000efe10a 100644 --- a/entproto/internal/entprototest/ent/portal_delete.go +++ b/entproto/internal/entprototest/ent/portal_delete.go @@ -27,7 +27,7 @@ func (pd *PortalDelete) Where(ps ...predicate.Portal) *PortalDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *PortalDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, PortalMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/portal_update.go b/entproto/internal/entprototest/ent/portal_update.go index 9b592aad7..80c51686c 100644 --- a/entproto/internal/entprototest/ent/portal_update.go +++ b/entproto/internal/entprototest/ent/portal_update.go @@ -34,12 +34,28 @@ func (pu *PortalUpdate) SetName(s string) *PortalUpdate { return pu } +// SetNillableName sets the "name" field if the given value is not nil. +func (pu *PortalUpdate) SetNillableName(s *string) *PortalUpdate { + if s != nil { + pu.SetName(*s) + } + return pu +} + // SetDescription sets the "description" field. func (pu *PortalUpdate) SetDescription(s string) *PortalUpdate { pu.mutation.SetDescription(s) return pu } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (pu *PortalUpdate) SetNillableDescription(s *string) *PortalUpdate { + if s != nil { + pu.SetDescription(*s) + } + return pu +} + // SetCategoryID sets the "category" edge to the Category entity by ID. func (pu *PortalUpdate) SetCategoryID(id int) *PortalUpdate { pu.mutation.SetCategoryID(id) @@ -72,7 +88,7 @@ func (pu *PortalUpdate) ClearCategory() *PortalUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PortalUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, PortalMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -167,12 +183,28 @@ func (puo *PortalUpdateOne) SetName(s string) *PortalUpdateOne { return puo } +// SetNillableName sets the "name" field if the given value is not nil. +func (puo *PortalUpdateOne) SetNillableName(s *string) *PortalUpdateOne { + if s != nil { + puo.SetName(*s) + } + return puo +} + // SetDescription sets the "description" field. func (puo *PortalUpdateOne) SetDescription(s string) *PortalUpdateOne { puo.mutation.SetDescription(s) return puo } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (puo *PortalUpdateOne) SetNillableDescription(s *string) *PortalUpdateOne { + if s != nil { + puo.SetDescription(*s) + } + return puo +} + // SetCategoryID sets the "category" edge to the Category entity by ID. func (puo *PortalUpdateOne) SetCategoryID(id int) *PortalUpdateOne { puo.mutation.SetCategoryID(id) @@ -218,7 +250,7 @@ func (puo *PortalUpdateOne) Select(field string, fields ...string) *PortalUpdate // Save executes the query and returns the updated Portal entity. func (puo *PortalUpdateOne) Save(ctx context.Context) (*Portal, error) { - return withHooks[*Portal, PortalMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/runtime/runtime.go b/entproto/internal/entprototest/ent/runtime/runtime.go index feefa3843..0f3bdb3bc 100644 --- a/entproto/internal/entprototest/ent/runtime/runtime.go +++ b/entproto/internal/entprototest/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entproto/internal/entprototest/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entproto/internal/entprototest/ent/skipedgeexample/where.go b/entproto/internal/entprototest/ent/skipedgeexample/where.go index ed1877f7c..1e6c4aa79 100644 --- a/entproto/internal/entprototest/ent/skipedgeexample/where.go +++ b/entproto/internal/entprototest/ent/skipedgeexample/where.go @@ -78,32 +78,15 @@ func HasUserWith(preds ...predicate.User) predicate.SkipEdgeExample { // And groups predicates with the AND operator between them. func And(predicates ...predicate.SkipEdgeExample) predicate.SkipEdgeExample { - return predicate.SkipEdgeExample(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.SkipEdgeExample(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.SkipEdgeExample) predicate.SkipEdgeExample { - return predicate.SkipEdgeExample(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.SkipEdgeExample(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.SkipEdgeExample) predicate.SkipEdgeExample { - return predicate.SkipEdgeExample(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.SkipEdgeExample(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/skipedgeexample_create.go b/entproto/internal/entprototest/ent/skipedgeexample_create.go index 0bdb2113b..0518ae6d3 100644 --- a/entproto/internal/entprototest/ent/skipedgeexample_create.go +++ b/entproto/internal/entprototest/ent/skipedgeexample_create.go @@ -45,7 +45,7 @@ func (seec *SkipEdgeExampleCreate) Mutation() *SkipEdgeExampleMutation { // Save creates the SkipEdgeExample in the database. func (seec *SkipEdgeExampleCreate) Save(ctx context.Context) (*SkipEdgeExample, error) { - return withHooks[*SkipEdgeExample, SkipEdgeExampleMutation](ctx, seec.sqlSave, seec.mutation, seec.hooks) + return withHooks(ctx, seec.sqlSave, seec.mutation, seec.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -121,11 +121,15 @@ func (seec *SkipEdgeExampleCreate) createSpec() (*SkipEdgeExample, *sqlgraph.Cre // SkipEdgeExampleCreateBulk is the builder for creating many SkipEdgeExample entities in bulk. type SkipEdgeExampleCreateBulk struct { config + err error builders []*SkipEdgeExampleCreate } // Save creates the SkipEdgeExample entities in the database. func (seecb *SkipEdgeExampleCreateBulk) Save(ctx context.Context) ([]*SkipEdgeExample, error) { + if seecb.err != nil { + return nil, seecb.err + } specs := make([]*sqlgraph.CreateSpec, len(seecb.builders)) nodes := make([]*SkipEdgeExample, len(seecb.builders)) mutators := make([]Mutator, len(seecb.builders)) diff --git a/entproto/internal/entprototest/ent/skipedgeexample_delete.go b/entproto/internal/entprototest/ent/skipedgeexample_delete.go index 8baaf49a0..b8b785eb8 100644 --- a/entproto/internal/entprototest/ent/skipedgeexample_delete.go +++ b/entproto/internal/entprototest/ent/skipedgeexample_delete.go @@ -27,7 +27,7 @@ func (seed *SkipEdgeExampleDelete) Where(ps ...predicate.SkipEdgeExample) *SkipE // Exec executes the deletion query and returns how many vertices were deleted. func (seed *SkipEdgeExampleDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, SkipEdgeExampleMutation](ctx, seed.sqlExec, seed.mutation, seed.hooks) + return withHooks(ctx, seed.sqlExec, seed.mutation, seed.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/skipedgeexample_update.go b/entproto/internal/entprototest/ent/skipedgeexample_update.go index d0f9c3c86..b57bafa7b 100644 --- a/entproto/internal/entprototest/ent/skipedgeexample_update.go +++ b/entproto/internal/entprototest/ent/skipedgeexample_update.go @@ -60,7 +60,7 @@ func (seeu *SkipEdgeExampleUpdate) ClearUser() *SkipEdgeExampleUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (seeu *SkipEdgeExampleUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, SkipEdgeExampleMutation](ctx, seeu.sqlSave, seeu.mutation, seeu.hooks) + return withHooks(ctx, seeu.sqlSave, seeu.mutation, seeu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -188,7 +188,7 @@ func (seeuo *SkipEdgeExampleUpdateOne) Select(field string, fields ...string) *S // Save executes the query and returns the updated SkipEdgeExample entity. func (seeuo *SkipEdgeExampleUpdateOne) Save(ctx context.Context) (*SkipEdgeExample, error) { - return withHooks[*SkipEdgeExample, SkipEdgeExampleMutation](ctx, seeuo.sqlSave, seeuo.mutation, seeuo.hooks) + return withHooks(ctx, seeuo.sqlSave, seeuo.mutation, seeuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/twomethodservice/where.go b/entproto/internal/entprototest/ent/twomethodservice/where.go index 0adac928f..7093b86cb 100644 --- a/entproto/internal/entprototest/ent/twomethodservice/where.go +++ b/entproto/internal/entprototest/ent/twomethodservice/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.TwoMethodService { // And groups predicates with the AND operator between them. func And(predicates ...predicate.TwoMethodService) predicate.TwoMethodService { - return predicate.TwoMethodService(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.TwoMethodService(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.TwoMethodService) predicate.TwoMethodService { - return predicate.TwoMethodService(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.TwoMethodService(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.TwoMethodService) predicate.TwoMethodService { - return predicate.TwoMethodService(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.TwoMethodService(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/twomethodservice_create.go b/entproto/internal/entprototest/ent/twomethodservice_create.go index 381200b68..d42b42060 100644 --- a/entproto/internal/entprototest/ent/twomethodservice_create.go +++ b/entproto/internal/entprototest/ent/twomethodservice_create.go @@ -25,7 +25,7 @@ func (tmsc *TwoMethodServiceCreate) Mutation() *TwoMethodServiceMutation { // Save creates the TwoMethodService in the database. func (tmsc *TwoMethodServiceCreate) Save(ctx context.Context) (*TwoMethodService, error) { - return withHooks[*TwoMethodService, TwoMethodServiceMutation](ctx, tmsc.sqlSave, tmsc.mutation, tmsc.hooks) + return withHooks(ctx, tmsc.sqlSave, tmsc.mutation, tmsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (tmsc *TwoMethodServiceCreate) createSpec() (*TwoMethodService, *sqlgraph.C // TwoMethodServiceCreateBulk is the builder for creating many TwoMethodService entities in bulk. type TwoMethodServiceCreateBulk struct { config + err error builders []*TwoMethodServiceCreate } // Save creates the TwoMethodService entities in the database. func (tmscb *TwoMethodServiceCreateBulk) Save(ctx context.Context) ([]*TwoMethodService, error) { + if tmscb.err != nil { + return nil, tmscb.err + } specs := make([]*sqlgraph.CreateSpec, len(tmscb.builders)) nodes := make([]*TwoMethodService, len(tmscb.builders)) mutators := make([]Mutator, len(tmscb.builders)) diff --git a/entproto/internal/entprototest/ent/twomethodservice_delete.go b/entproto/internal/entprototest/ent/twomethodservice_delete.go index 5ae2b736a..54d98dd9b 100644 --- a/entproto/internal/entprototest/ent/twomethodservice_delete.go +++ b/entproto/internal/entprototest/ent/twomethodservice_delete.go @@ -27,7 +27,7 @@ func (tmsd *TwoMethodServiceDelete) Where(ps ...predicate.TwoMethodService) *Two // Exec executes the deletion query and returns how many vertices were deleted. func (tmsd *TwoMethodServiceDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TwoMethodServiceMutation](ctx, tmsd.sqlExec, tmsd.mutation, tmsd.hooks) + return withHooks(ctx, tmsd.sqlExec, tmsd.mutation, tmsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/twomethodservice_update.go b/entproto/internal/entprototest/ent/twomethodservice_update.go index 319d815f9..f5fec2003 100644 --- a/entproto/internal/entprototest/ent/twomethodservice_update.go +++ b/entproto/internal/entprototest/ent/twomethodservice_update.go @@ -34,7 +34,7 @@ func (tmsu *TwoMethodServiceUpdate) Mutation() *TwoMethodServiceMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (tmsu *TwoMethodServiceUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TwoMethodServiceMutation](ctx, tmsu.sqlSave, tmsu.mutation, tmsu.hooks) + return withHooks(ctx, tmsu.sqlSave, tmsu.mutation, tmsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (tmsuo *TwoMethodServiceUpdateOne) Select(field string, fields ...string) * // Save executes the query and returns the updated TwoMethodService entity. func (tmsuo *TwoMethodServiceUpdateOne) Save(ctx context.Context) (*TwoMethodService, error) { - return withHooks[*TwoMethodService, TwoMethodServiceMutation](ctx, tmsuo.sqlSave, tmsuo.mutation, tmsuo.hooks) + return withHooks(ctx, tmsuo.sqlSave, tmsuo.mutation, tmsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/user/where.go b/entproto/internal/entprototest/ent/user/where.go index cc0e09141..dcb17a740 100644 --- a/entproto/internal/entprototest/ent/user/where.go +++ b/entproto/internal/entprototest/ent/user/where.go @@ -294,32 +294,15 @@ func HasSkipEdgeWith(preds ...predicate.SkipEdgeExample) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/user_create.go b/entproto/internal/entprototest/ent/user_create.go index a39b33e02..db1b592fe 100644 --- a/entproto/internal/entprototest/ent/user_create.go +++ b/entproto/internal/entprototest/ent/user_create.go @@ -109,7 +109,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -240,11 +240,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entproto/internal/entprototest/ent/user_delete.go b/entproto/internal/entprototest/ent/user_delete.go index 683bb6464..95408a2ae 100644 --- a/entproto/internal/entprototest/ent/user_delete.go +++ b/entproto/internal/entprototest/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/user_update.go b/entproto/internal/entprototest/ent/user_update.go index a458d7806..85395ebfb 100644 --- a/entproto/internal/entprototest/ent/user_update.go +++ b/entproto/internal/entprototest/ent/user_update.go @@ -37,12 +37,28 @@ func (uu *UserUpdate) SetUserName(s string) *UserUpdate { return uu } +// SetNillableUserName sets the "user_name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableUserName(s *string) *UserUpdate { + if s != nil { + uu.SetUserName(*s) + } + return uu +} + // SetStatus sets the "status" field. func (uu *UserUpdate) SetStatus(u user.Status) *UserUpdate { uu.mutation.SetStatus(u) return uu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (uu *UserUpdate) SetNillableStatus(u *user.Status) *UserUpdate { + if u != nil { + uu.SetStatus(*u) + } + return uu +} + // SetUnnecessary sets the "unnecessary" field. func (uu *UserUpdate) SetUnnecessary(s string) *UserUpdate { uu.mutation.SetUnnecessary(s) @@ -156,7 +172,7 @@ func (uu *UserUpdate) ClearSkipEdge() *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -344,12 +360,28 @@ func (uuo *UserUpdateOne) SetUserName(s string) *UserUpdateOne { return uuo } +// SetNillableUserName sets the "user_name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableUserName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetUserName(*s) + } + return uuo +} + // SetStatus sets the "status" field. func (uuo *UserUpdateOne) SetStatus(u user.Status) *UserUpdateOne { uuo.mutation.SetStatus(u) return uuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableStatus(u *user.Status) *UserUpdateOne { + if u != nil { + uuo.SetStatus(*u) + } + return uuo +} + // SetUnnecessary sets the "unnecessary" field. func (uuo *UserUpdateOne) SetUnnecessary(s string) *UserUpdateOne { uuo.mutation.SetUnnecessary(s) @@ -476,7 +508,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/validmessage/where.go b/entproto/internal/entprototest/ent/validmessage/where.go index 6f56172e7..564ac3be3 100644 --- a/entproto/internal/entprototest/ent/validmessage/where.go +++ b/entproto/internal/entprototest/ent/validmessage/where.go @@ -317,32 +317,15 @@ func Opti8NotNil() predicate.ValidMessage { // And groups predicates with the AND operator between them. func And(predicates ...predicate.ValidMessage) predicate.ValidMessage { - return predicate.ValidMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.ValidMessage(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.ValidMessage) predicate.ValidMessage { - return predicate.ValidMessage(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.ValidMessage(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.ValidMessage) predicate.ValidMessage { - return predicate.ValidMessage(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.ValidMessage(sql.NotPredicates(p)) } diff --git a/entproto/internal/entprototest/ent/validmessage_create.go b/entproto/internal/entprototest/ent/validmessage_create.go index a92665150..9f408e464 100644 --- a/entproto/internal/entprototest/ent/validmessage_create.go +++ b/entproto/internal/entprototest/ent/validmessage_create.go @@ -66,7 +66,7 @@ func (vmc *ValidMessageCreate) Mutation() *ValidMessageMutation { // Save creates the ValidMessage in the database. func (vmc *ValidMessageCreate) Save(ctx context.Context) (*ValidMessage, error) { - return withHooks[*ValidMessage, ValidMessageMutation](ctx, vmc.sqlSave, vmc.mutation, vmc.hooks) + return withHooks(ctx, vmc.sqlSave, vmc.mutation, vmc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -157,11 +157,15 @@ func (vmc *ValidMessageCreate) createSpec() (*ValidMessage, *sqlgraph.CreateSpec // ValidMessageCreateBulk is the builder for creating many ValidMessage entities in bulk. type ValidMessageCreateBulk struct { config + err error builders []*ValidMessageCreate } // Save creates the ValidMessage entities in the database. func (vmcb *ValidMessageCreateBulk) Save(ctx context.Context) ([]*ValidMessage, error) { + if vmcb.err != nil { + return nil, vmcb.err + } specs := make([]*sqlgraph.CreateSpec, len(vmcb.builders)) nodes := make([]*ValidMessage, len(vmcb.builders)) mutators := make([]Mutator, len(vmcb.builders)) diff --git a/entproto/internal/entprototest/ent/validmessage_delete.go b/entproto/internal/entprototest/ent/validmessage_delete.go index ae32e5cb4..46c2cf739 100644 --- a/entproto/internal/entprototest/ent/validmessage_delete.go +++ b/entproto/internal/entprototest/ent/validmessage_delete.go @@ -27,7 +27,7 @@ func (vmd *ValidMessageDelete) Where(ps ...predicate.ValidMessage) *ValidMessage // Exec executes the deletion query and returns how many vertices were deleted. func (vmd *ValidMessageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, ValidMessageMutation](ctx, vmd.sqlExec, vmd.mutation, vmd.hooks) + return withHooks(ctx, vmd.sqlExec, vmd.mutation, vmd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/entprototest/ent/validmessage_update.go b/entproto/internal/entprototest/ent/validmessage_update.go index 2b9e82b59..98709d24d 100644 --- a/entproto/internal/entprototest/ent/validmessage_update.go +++ b/entproto/internal/entprototest/ent/validmessage_update.go @@ -35,18 +35,42 @@ func (vmu *ValidMessageUpdate) SetName(s string) *ValidMessageUpdate { return vmu } +// SetNillableName sets the "name" field if the given value is not nil. +func (vmu *ValidMessageUpdate) SetNillableName(s *string) *ValidMessageUpdate { + if s != nil { + vmu.SetName(*s) + } + return vmu +} + // SetTs sets the "ts" field. func (vmu *ValidMessageUpdate) SetTs(t time.Time) *ValidMessageUpdate { vmu.mutation.SetTs(t) return vmu } +// SetNillableTs sets the "ts" field if the given value is not nil. +func (vmu *ValidMessageUpdate) SetNillableTs(t *time.Time) *ValidMessageUpdate { + if t != nil { + vmu.SetTs(*t) + } + return vmu +} + // SetUUID sets the "uuid" field. func (vmu *ValidMessageUpdate) SetUUID(u uuid.UUID) *ValidMessageUpdate { vmu.mutation.SetUUID(u) return vmu } +// SetNillableUUID sets the "uuid" field if the given value is not nil. +func (vmu *ValidMessageUpdate) SetNillableUUID(u *uuid.UUID) *ValidMessageUpdate { + if u != nil { + vmu.SetUUID(*u) + } + return vmu +} + // SetU8 sets the "u8" field. func (vmu *ValidMessageUpdate) SetU8(u uint8) *ValidMessageUpdate { vmu.mutation.ResetU8() @@ -54,6 +78,14 @@ func (vmu *ValidMessageUpdate) SetU8(u uint8) *ValidMessageUpdate { return vmu } +// SetNillableU8 sets the "u8" field if the given value is not nil. +func (vmu *ValidMessageUpdate) SetNillableU8(u *uint8) *ValidMessageUpdate { + if u != nil { + vmu.SetU8(*u) + } + return vmu +} + // AddU8 adds u to the "u8" field. func (vmu *ValidMessageUpdate) AddU8(u int8) *ValidMessageUpdate { vmu.mutation.AddU8(u) @@ -94,7 +126,7 @@ func (vmu *ValidMessageUpdate) Mutation() *ValidMessageMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (vmu *ValidMessageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, ValidMessageMutation](ctx, vmu.sqlSave, vmu.mutation, vmu.hooks) + return withHooks(ctx, vmu.sqlSave, vmu.mutation, vmu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -178,18 +210,42 @@ func (vmuo *ValidMessageUpdateOne) SetName(s string) *ValidMessageUpdateOne { return vmuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (vmuo *ValidMessageUpdateOne) SetNillableName(s *string) *ValidMessageUpdateOne { + if s != nil { + vmuo.SetName(*s) + } + return vmuo +} + // SetTs sets the "ts" field. func (vmuo *ValidMessageUpdateOne) SetTs(t time.Time) *ValidMessageUpdateOne { vmuo.mutation.SetTs(t) return vmuo } +// SetNillableTs sets the "ts" field if the given value is not nil. +func (vmuo *ValidMessageUpdateOne) SetNillableTs(t *time.Time) *ValidMessageUpdateOne { + if t != nil { + vmuo.SetTs(*t) + } + return vmuo +} + // SetUUID sets the "uuid" field. func (vmuo *ValidMessageUpdateOne) SetUUID(u uuid.UUID) *ValidMessageUpdateOne { vmuo.mutation.SetUUID(u) return vmuo } +// SetNillableUUID sets the "uuid" field if the given value is not nil. +func (vmuo *ValidMessageUpdateOne) SetNillableUUID(u *uuid.UUID) *ValidMessageUpdateOne { + if u != nil { + vmuo.SetUUID(*u) + } + return vmuo +} + // SetU8 sets the "u8" field. func (vmuo *ValidMessageUpdateOne) SetU8(u uint8) *ValidMessageUpdateOne { vmuo.mutation.ResetU8() @@ -197,6 +253,14 @@ func (vmuo *ValidMessageUpdateOne) SetU8(u uint8) *ValidMessageUpdateOne { return vmuo } +// SetNillableU8 sets the "u8" field if the given value is not nil. +func (vmuo *ValidMessageUpdateOne) SetNillableU8(u *uint8) *ValidMessageUpdateOne { + if u != nil { + vmuo.SetU8(*u) + } + return vmuo +} + // AddU8 adds u to the "u8" field. func (vmuo *ValidMessageUpdateOne) AddU8(u int8) *ValidMessageUpdateOne { vmuo.mutation.AddU8(u) @@ -250,7 +314,7 @@ func (vmuo *ValidMessageUpdateOne) Select(field string, fields ...string) *Valid // Save executes the query and returns the updated ValidMessage entity. func (vmuo *ValidMessageUpdateOne) Save(ctx context.Context) (*ValidMessage, error) { - return withHooks[*ValidMessage, ValidMessageMutation](ctx, vmuo.sqlSave, vmuo.mutation, vmuo.hooks) + return withHooks(ctx, vmuo.sqlSave, vmuo.mutation, vmuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/attachment/where.go b/entproto/internal/todo/ent/attachment/where.go index 213d959b6..d0f3191ef 100644 --- a/entproto/internal/todo/ent/attachment/where.go +++ b/entproto/internal/todo/ent/attachment/where.go @@ -102,32 +102,15 @@ func HasRecipientsWith(preds ...predicate.User) predicate.Attachment { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Attachment) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Attachment(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Attachment) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Attachment(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Attachment) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Attachment(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/attachment_create.go b/entproto/internal/todo/ent/attachment_create.go index 624b4811a..3778c39b5 100644 --- a/entproto/internal/todo/ent/attachment_create.go +++ b/entproto/internal/todo/ent/attachment_create.go @@ -76,7 +76,7 @@ func (ac *AttachmentCreate) Mutation() *AttachmentMutation { // Save creates the Attachment in the database. func (ac *AttachmentCreate) Save(ctx context.Context) (*Attachment, error) { ac.defaults() - return withHooks[*Attachment, AttachmentMutation](ctx, ac.sqlSave, ac.mutation, ac.hooks) + return withHooks(ctx, ac.sqlSave, ac.mutation, ac.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -185,11 +185,15 @@ func (ac *AttachmentCreate) createSpec() (*Attachment, *sqlgraph.CreateSpec) { // AttachmentCreateBulk is the builder for creating many Attachment entities in bulk. type AttachmentCreateBulk struct { config + err error builders []*AttachmentCreate } // Save creates the Attachment entities in the database. func (acb *AttachmentCreateBulk) Save(ctx context.Context) ([]*Attachment, error) { + if acb.err != nil { + return nil, acb.err + } specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) nodes := make([]*Attachment, len(acb.builders)) mutators := make([]Mutator, len(acb.builders)) diff --git a/entproto/internal/todo/ent/attachment_delete.go b/entproto/internal/todo/ent/attachment_delete.go index b30dba4e2..70dd94a2a 100644 --- a/entproto/internal/todo/ent/attachment_delete.go +++ b/entproto/internal/todo/ent/attachment_delete.go @@ -27,7 +27,7 @@ func (ad *AttachmentDelete) Where(ps ...predicate.Attachment) *AttachmentDelete // Exec executes the deletion query and returns how many vertices were deleted. func (ad *AttachmentDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, AttachmentMutation](ctx, ad.sqlExec, ad.mutation, ad.hooks) + return withHooks(ctx, ad.sqlExec, ad.mutation, ad.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/attachment_update.go b/entproto/internal/todo/ent/attachment_update.go index 61be42beb..b520993c2 100644 --- a/entproto/internal/todo/ent/attachment_update.go +++ b/entproto/internal/todo/ent/attachment_update.go @@ -96,7 +96,7 @@ func (au *AttachmentUpdate) RemoveRecipients(u ...*User) *AttachmentUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (au *AttachmentUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, AttachmentMutation](ctx, au.sqlSave, au.mutation, au.hooks) + return withHooks(ctx, au.sqlSave, au.mutation, au.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -305,7 +305,7 @@ func (auo *AttachmentUpdateOne) Select(field string, fields ...string) *Attachme // Save executes the query and returns the updated Attachment entity. func (auo *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) { - return withHooks[*Attachment, AttachmentMutation](ctx, auo.sqlSave, auo.mutation, auo.hooks) + return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/client.go b/entproto/internal/todo/ent/client.go index de3456ccb..ee901c4aa 100644 --- a/entproto/internal/todo/ent/client.go +++ b/entproto/internal/todo/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/entproto/internal/todo/ent/migrate" "entgo.io/ent" @@ -138,11 +139,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -296,6 +300,21 @@ func (c *AttachmentClient) CreateBulk(builders ...*AttachmentCreate) *Attachment return &AttachmentCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *AttachmentClient) MapCreateBulk(slice any, setFunc func(*AttachmentCreate, int)) *AttachmentCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AttachmentCreateBulk{err: fmt.Errorf("calling to AttachmentClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AttachmentCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AttachmentCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Attachment. func (c *AttachmentClient) Update() *AttachmentUpdate { mutation := newAttachmentMutation(c.config, OpUpdate) @@ -446,6 +465,21 @@ func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { return &GroupCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Group. func (c *GroupClient) Update() *GroupUpdate { mutation := newGroupMutation(c.config, OpUpdate) @@ -580,6 +614,21 @@ func (c *MultiWordSchemaClient) CreateBulk(builders ...*MultiWordSchemaCreate) * return &MultiWordSchemaCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MultiWordSchemaClient) MapCreateBulk(slice any, setFunc func(*MultiWordSchemaCreate, int)) *MultiWordSchemaCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MultiWordSchemaCreateBulk{err: fmt.Errorf("calling to MultiWordSchemaClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MultiWordSchemaCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MultiWordSchemaCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for MultiWordSchema. func (c *MultiWordSchemaClient) Update() *MultiWordSchemaUpdate { mutation := newMultiWordSchemaMutation(c.config, OpUpdate) @@ -698,6 +747,21 @@ func (c *NilExampleClient) CreateBulk(builders ...*NilExampleCreate) *NilExample return &NilExampleCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *NilExampleClient) MapCreateBulk(slice any, setFunc func(*NilExampleCreate, int)) *NilExampleCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &NilExampleCreateBulk{err: fmt.Errorf("calling to NilExampleClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*NilExampleCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &NilExampleCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for NilExample. func (c *NilExampleClient) Update() *NilExampleUpdate { mutation := newNilExampleMutation(c.config, OpUpdate) @@ -816,6 +880,21 @@ func (c *PetClient) CreateBulk(builders ...*PetCreate) *PetCreateBulk { return &PetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PetClient) MapCreateBulk(slice any, setFunc func(*PetCreate, int)) *PetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PetCreateBulk{err: fmt.Errorf("calling to PetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Pet. func (c *PetClient) Update() *PetUpdate { mutation := newPetMutation(c.config, OpUpdate) @@ -966,6 +1045,21 @@ func (c *PonyClient) CreateBulk(builders ...*PonyCreate) *PonyCreateBulk { return &PonyCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PonyClient) MapCreateBulk(slice any, setFunc func(*PonyCreate, int)) *PonyCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PonyCreateBulk{err: fmt.Errorf("calling to PonyClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PonyCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PonyCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Pony. func (c *PonyClient) Update() *PonyUpdate { mutation := newPonyMutation(c.config, OpUpdate) @@ -1084,6 +1178,21 @@ func (c *SkipEdgeExampleClient) CreateBulk(builders ...*SkipEdgeExampleCreate) * return &SkipEdgeExampleCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *SkipEdgeExampleClient) MapCreateBulk(slice any, setFunc func(*SkipEdgeExampleCreate, int)) *SkipEdgeExampleCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SkipEdgeExampleCreateBulk{err: fmt.Errorf("calling to SkipEdgeExampleClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SkipEdgeExampleCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SkipEdgeExampleCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for SkipEdgeExample. func (c *SkipEdgeExampleClient) Update() *SkipEdgeExampleUpdate { mutation := newSkipEdgeExampleMutation(c.config, OpUpdate) @@ -1218,6 +1327,21 @@ func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk { return &TodoCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TodoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TodoCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Todo. func (c *TodoClient) Update() *TodoUpdate { mutation := newTodoMutation(c.config, OpUpdate) @@ -1352,6 +1476,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/entproto/internal/todo/ent/group/where.go b/entproto/internal/todo/ent/group/where.go index d3493f1d6..9eb652e5a 100644 --- a/entproto/internal/todo/ent/group/where.go +++ b/entproto/internal/todo/ent/group/where.go @@ -148,32 +148,15 @@ func HasUsersWith(preds ...predicate.User) predicate.Group { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Group(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/group_create.go b/entproto/internal/todo/ent/group_create.go index 24c023d8d..56bb43cf0 100644 --- a/entproto/internal/todo/ent/group_create.go +++ b/entproto/internal/todo/ent/group_create.go @@ -48,7 +48,7 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { - return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) + return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -130,11 +130,15 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { // GroupCreateBulk is the builder for creating many Group entities in bulk. type GroupCreateBulk struct { config + err error builders []*GroupCreate } // Save creates the Group entities in the database. func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { + if gcb.err != nil { + return nil, gcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gcb.builders)) nodes := make([]*Group, len(gcb.builders)) mutators := make([]Mutator, len(gcb.builders)) diff --git a/entproto/internal/todo/ent/group_delete.go b/entproto/internal/todo/ent/group_delete.go index 030872eb7..e926f2bda 100644 --- a/entproto/internal/todo/ent/group_delete.go +++ b/entproto/internal/todo/ent/group_delete.go @@ -27,7 +27,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) + return withHooks(ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/group_update.go b/entproto/internal/todo/ent/group_update.go index a3e3ddd95..114961bdc 100644 --- a/entproto/internal/todo/ent/group_update.go +++ b/entproto/internal/todo/ent/group_update.go @@ -34,6 +34,14 @@ func (gu *GroupUpdate) SetName(s string) *GroupUpdate { return gu } +// SetNillableName sets the "name" field if the given value is not nil. +func (gu *GroupUpdate) SetNillableName(s *string) *GroupUpdate { + if s != nil { + gu.SetName(*s) + } + return gu +} + // AddUserIDs adds the "users" edge to the User entity by IDs. func (gu *GroupUpdate) AddUserIDs(ids ...uint32) *GroupUpdate { gu.mutation.AddUserIDs(ids...) @@ -77,7 +85,7 @@ func (gu *GroupUpdate) RemoveUsers(u ...*User) *GroupUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) + return withHooks(ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -185,6 +193,14 @@ func (guo *GroupUpdateOne) SetName(s string) *GroupUpdateOne { return guo } +// SetNillableName sets the "name" field if the given value is not nil. +func (guo *GroupUpdateOne) SetNillableName(s *string) *GroupUpdateOne { + if s != nil { + guo.SetName(*s) + } + return guo +} + // AddUserIDs adds the "users" edge to the User entity by IDs. func (guo *GroupUpdateOne) AddUserIDs(ids ...uint32) *GroupUpdateOne { guo.mutation.AddUserIDs(ids...) @@ -241,7 +257,7 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { - return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) + return withHooks(ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/multiwordschema/where.go b/entproto/internal/todo/ent/multiwordschema/where.go index 3358036eb..89af9dd12 100644 --- a/entproto/internal/todo/ent/multiwordschema/where.go +++ b/entproto/internal/todo/ent/multiwordschema/where.go @@ -74,32 +74,15 @@ func UnitNotIn(vs ...Unit) predicate.MultiWordSchema { // And groups predicates with the AND operator between them. func And(predicates ...predicate.MultiWordSchema) predicate.MultiWordSchema { - return predicate.MultiWordSchema(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MultiWordSchema(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.MultiWordSchema) predicate.MultiWordSchema { - return predicate.MultiWordSchema(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.MultiWordSchema(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.MultiWordSchema) predicate.MultiWordSchema { - return predicate.MultiWordSchema(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.MultiWordSchema(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/multiwordschema_create.go b/entproto/internal/todo/ent/multiwordschema_create.go index 57c540482..acbcf3a2b 100644 --- a/entproto/internal/todo/ent/multiwordschema_create.go +++ b/entproto/internal/todo/ent/multiwordschema_create.go @@ -41,7 +41,7 @@ func (mwsc *MultiWordSchemaCreate) Mutation() *MultiWordSchemaMutation { // Save creates the MultiWordSchema in the database. func (mwsc *MultiWordSchemaCreate) Save(ctx context.Context) (*MultiWordSchema, error) { mwsc.defaults() - return withHooks[*MultiWordSchema, MultiWordSchemaMutation](ctx, mwsc.sqlSave, mwsc.mutation, mwsc.hooks) + return withHooks(ctx, mwsc.sqlSave, mwsc.mutation, mwsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -120,11 +120,15 @@ func (mwsc *MultiWordSchemaCreate) createSpec() (*MultiWordSchema, *sqlgraph.Cre // MultiWordSchemaCreateBulk is the builder for creating many MultiWordSchema entities in bulk. type MultiWordSchemaCreateBulk struct { config + err error builders []*MultiWordSchemaCreate } // Save creates the MultiWordSchema entities in the database. func (mwscb *MultiWordSchemaCreateBulk) Save(ctx context.Context) ([]*MultiWordSchema, error) { + if mwscb.err != nil { + return nil, mwscb.err + } specs := make([]*sqlgraph.CreateSpec, len(mwscb.builders)) nodes := make([]*MultiWordSchema, len(mwscb.builders)) mutators := make([]Mutator, len(mwscb.builders)) diff --git a/entproto/internal/todo/ent/multiwordschema_delete.go b/entproto/internal/todo/ent/multiwordschema_delete.go index e3f3d41db..da4a5f12d 100644 --- a/entproto/internal/todo/ent/multiwordschema_delete.go +++ b/entproto/internal/todo/ent/multiwordschema_delete.go @@ -27,7 +27,7 @@ func (mwsd *MultiWordSchemaDelete) Where(ps ...predicate.MultiWordSchema) *Multi // Exec executes the deletion query and returns how many vertices were deleted. func (mwsd *MultiWordSchemaDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MultiWordSchemaMutation](ctx, mwsd.sqlExec, mwsd.mutation, mwsd.hooks) + return withHooks(ctx, mwsd.sqlExec, mwsd.mutation, mwsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/multiwordschema_update.go b/entproto/internal/todo/ent/multiwordschema_update.go index 579d98260..b4523907c 100644 --- a/entproto/internal/todo/ent/multiwordschema_update.go +++ b/entproto/internal/todo/ent/multiwordschema_update.go @@ -48,7 +48,7 @@ func (mwsu *MultiWordSchemaUpdate) Mutation() *MultiWordSchemaMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (mwsu *MultiWordSchemaUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MultiWordSchemaMutation](ctx, mwsu.sqlSave, mwsu.mutation, mwsu.hooks) + return withHooks(ctx, mwsu.sqlSave, mwsu.mutation, mwsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -152,7 +152,7 @@ func (mwsuo *MultiWordSchemaUpdateOne) Select(field string, fields ...string) *M // Save executes the query and returns the updated MultiWordSchema entity. func (mwsuo *MultiWordSchemaUpdateOne) Save(ctx context.Context) (*MultiWordSchema, error) { - return withHooks[*MultiWordSchema, MultiWordSchemaMutation](ctx, mwsuo.sqlSave, mwsuo.mutation, mwsuo.hooks) + return withHooks(ctx, mwsuo.sqlSave, mwsuo.mutation, mwsuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/nilexample/where.go b/entproto/internal/todo/ent/nilexample/where.go index 41b69cc00..746891ee5 100644 --- a/entproto/internal/todo/ent/nilexample/where.go +++ b/entproto/internal/todo/ent/nilexample/where.go @@ -191,32 +191,15 @@ func TimeNilNotNil() predicate.NilExample { // And groups predicates with the AND operator between them. func And(predicates ...predicate.NilExample) predicate.NilExample { - return predicate.NilExample(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.NilExample(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.NilExample) predicate.NilExample { - return predicate.NilExample(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.NilExample(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.NilExample) predicate.NilExample { - return predicate.NilExample(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.NilExample(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/nilexample_create.go b/entproto/internal/todo/ent/nilexample_create.go index e8798bd84..5cb001641 100644 --- a/entproto/internal/todo/ent/nilexample_create.go +++ b/entproto/internal/todo/ent/nilexample_create.go @@ -54,7 +54,7 @@ func (nec *NilExampleCreate) Mutation() *NilExampleMutation { // Save creates the NilExample in the database. func (nec *NilExampleCreate) Save(ctx context.Context) (*NilExample, error) { - return withHooks[*NilExample, NilExampleMutation](ctx, nec.sqlSave, nec.mutation, nec.hooks) + return withHooks(ctx, nec.sqlSave, nec.mutation, nec.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -121,11 +121,15 @@ func (nec *NilExampleCreate) createSpec() (*NilExample, *sqlgraph.CreateSpec) { // NilExampleCreateBulk is the builder for creating many NilExample entities in bulk. type NilExampleCreateBulk struct { config + err error builders []*NilExampleCreate } // Save creates the NilExample entities in the database. func (necb *NilExampleCreateBulk) Save(ctx context.Context) ([]*NilExample, error) { + if necb.err != nil { + return nil, necb.err + } specs := make([]*sqlgraph.CreateSpec, len(necb.builders)) nodes := make([]*NilExample, len(necb.builders)) mutators := make([]Mutator, len(necb.builders)) diff --git a/entproto/internal/todo/ent/nilexample_delete.go b/entproto/internal/todo/ent/nilexample_delete.go index 755b4b3b7..2f7ed6e0b 100644 --- a/entproto/internal/todo/ent/nilexample_delete.go +++ b/entproto/internal/todo/ent/nilexample_delete.go @@ -27,7 +27,7 @@ func (ned *NilExampleDelete) Where(ps ...predicate.NilExample) *NilExampleDelete // Exec executes the deletion query and returns how many vertices were deleted. func (ned *NilExampleDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, NilExampleMutation](ctx, ned.sqlExec, ned.mutation, ned.hooks) + return withHooks(ctx, ned.sqlExec, ned.mutation, ned.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/nilexample_update.go b/entproto/internal/todo/ent/nilexample_update.go index 65f7d3339..a76679801 100644 --- a/entproto/internal/todo/ent/nilexample_update.go +++ b/entproto/internal/todo/ent/nilexample_update.go @@ -75,7 +75,7 @@ func (neu *NilExampleUpdate) Mutation() *NilExampleMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (neu *NilExampleUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, NilExampleMutation](ctx, neu.sqlSave, neu.mutation, neu.hooks) + return withHooks(ctx, neu.sqlSave, neu.mutation, neu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -201,7 +201,7 @@ func (neuo *NilExampleUpdateOne) Select(field string, fields ...string) *NilExam // Save executes the query and returns the updated NilExample entity. func (neuo *NilExampleUpdateOne) Save(ctx context.Context) (*NilExample, error) { - return withHooks[*NilExample, NilExampleMutation](ctx, neuo.sqlSave, neuo.mutation, neuo.hooks) + return withHooks(ctx, neuo.sqlSave, neuo.mutation, neuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/pet/where.go b/entproto/internal/todo/ent/pet/where.go index 5d35c8db7..c2c52d1f4 100644 --- a/entproto/internal/todo/ent/pet/where.go +++ b/entproto/internal/todo/ent/pet/where.go @@ -101,32 +101,15 @@ func HasAttachmentWith(preds ...predicate.Attachment) predicate.Pet { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pet(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Pet) predicate.Pet { - return predicate.Pet(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Pet(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/pet_create.go b/entproto/internal/todo/ent/pet_create.go index 61c28a39b..e63fbcc87 100644 --- a/entproto/internal/todo/ent/pet_create.go +++ b/entproto/internal/todo/ent/pet_create.go @@ -62,7 +62,7 @@ func (pc *PetCreate) Mutation() *PetMutation { // Save creates the Pet in the database. func (pc *PetCreate) Save(ctx context.Context) (*Pet, error) { - return withHooks[*Pet, PetMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -154,11 +154,15 @@ func (pc *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) { // PetCreateBulk is the builder for creating many Pet entities in bulk. type PetCreateBulk struct { config + err error builders []*PetCreate } // Save creates the Pet entities in the database. func (pcb *PetCreateBulk) Save(ctx context.Context) ([]*Pet, error) { + if pcb.err != nil { + return nil, pcb.err + } specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) nodes := make([]*Pet, len(pcb.builders)) mutators := make([]Mutator, len(pcb.builders)) diff --git a/entproto/internal/todo/ent/pet_delete.go b/entproto/internal/todo/ent/pet_delete.go index aeac61183..34c87ae8c 100644 --- a/entproto/internal/todo/ent/pet_delete.go +++ b/entproto/internal/todo/ent/pet_delete.go @@ -27,7 +27,7 @@ func (pd *PetDelete) Where(ps ...predicate.Pet) *PetDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *PetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/pet_update.go b/entproto/internal/todo/ent/pet_update.go index 134282849..a41b1cd0f 100644 --- a/entproto/internal/todo/ent/pet_update.go +++ b/entproto/internal/todo/ent/pet_update.go @@ -98,7 +98,7 @@ func (pu *PetUpdate) RemoveAttachment(a ...*Attachment) *PetUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, PetMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -307,7 +307,7 @@ func (puo *PetUpdateOne) Select(field string, fields ...string) *PetUpdateOne { // Save executes the query and returns the updated Pet entity. func (puo *PetUpdateOne) Save(ctx context.Context) (*Pet, error) { - return withHooks[*Pet, PetMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/pony/where.go b/entproto/internal/todo/ent/pony/where.go index 4e8c08df6..dc6da6b33 100644 --- a/entproto/internal/todo/ent/pony/where.go +++ b/entproto/internal/todo/ent/pony/where.go @@ -124,32 +124,15 @@ func NameContainsFold(v string) predicate.Pony { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Pony) predicate.Pony { - return predicate.Pony(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pony(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Pony) predicate.Pony { - return predicate.Pony(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Pony(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Pony) predicate.Pony { - return predicate.Pony(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Pony(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/pony_create.go b/entproto/internal/todo/ent/pony_create.go index 541b0f508..226d0dda6 100644 --- a/entproto/internal/todo/ent/pony_create.go +++ b/entproto/internal/todo/ent/pony_create.go @@ -32,7 +32,7 @@ func (pc *PonyCreate) Mutation() *PonyMutation { // Save creates the Pony in the database. func (pc *PonyCreate) Save(ctx context.Context) (*Pony, error) { - return withHooks[*Pony, PonyMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -98,11 +98,15 @@ func (pc *PonyCreate) createSpec() (*Pony, *sqlgraph.CreateSpec) { // PonyCreateBulk is the builder for creating many Pony entities in bulk. type PonyCreateBulk struct { config + err error builders []*PonyCreate } // Save creates the Pony entities in the database. func (pcb *PonyCreateBulk) Save(ctx context.Context) ([]*Pony, error) { + if pcb.err != nil { + return nil, pcb.err + } specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) nodes := make([]*Pony, len(pcb.builders)) mutators := make([]Mutator, len(pcb.builders)) diff --git a/entproto/internal/todo/ent/pony_delete.go b/entproto/internal/todo/ent/pony_delete.go index 86f3a192d..c348b6b7f 100644 --- a/entproto/internal/todo/ent/pony_delete.go +++ b/entproto/internal/todo/ent/pony_delete.go @@ -27,7 +27,7 @@ func (pd *PonyDelete) Where(ps ...predicate.Pony) *PonyDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *PonyDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, PonyMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/pony_update.go b/entproto/internal/todo/ent/pony_update.go index 2621c4d64..42dbedd3d 100644 --- a/entproto/internal/todo/ent/pony_update.go +++ b/entproto/internal/todo/ent/pony_update.go @@ -33,6 +33,14 @@ func (pu *PonyUpdate) SetName(s string) *PonyUpdate { return pu } +// SetNillableName sets the "name" field if the given value is not nil. +func (pu *PonyUpdate) SetNillableName(s *string) *PonyUpdate { + if s != nil { + pu.SetName(*s) + } + return pu +} + // Mutation returns the PonyMutation object of the builder. func (pu *PonyUpdate) Mutation() *PonyMutation { return pu.mutation @@ -40,7 +48,7 @@ func (pu *PonyUpdate) Mutation() *PonyMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PonyUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, PonyMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -103,6 +111,14 @@ func (puo *PonyUpdateOne) SetName(s string) *PonyUpdateOne { return puo } +// SetNillableName sets the "name" field if the given value is not nil. +func (puo *PonyUpdateOne) SetNillableName(s *string) *PonyUpdateOne { + if s != nil { + puo.SetName(*s) + } + return puo +} + // Mutation returns the PonyMutation object of the builder. func (puo *PonyUpdateOne) Mutation() *PonyMutation { return puo.mutation @@ -123,7 +139,7 @@ func (puo *PonyUpdateOne) Select(field string, fields ...string) *PonyUpdateOne // Save executes the query and returns the updated Pony entity. func (puo *PonyUpdateOne) Save(ctx context.Context) (*Pony, error) { - return withHooks[*Pony, PonyMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/runtime/runtime.go b/entproto/internal/todo/ent/runtime/runtime.go index 8ea0c6100..0c424130c 100644 --- a/entproto/internal/todo/ent/runtime/runtime.go +++ b/entproto/internal/todo/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/entproto/internal/todo/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/entproto/internal/todo/ent/skipedgeexample/where.go b/entproto/internal/todo/ent/skipedgeexample/where.go index f1e34241e..e4eae9387 100644 --- a/entproto/internal/todo/ent/skipedgeexample/where.go +++ b/entproto/internal/todo/ent/skipedgeexample/where.go @@ -78,32 +78,15 @@ func HasUserWith(preds ...predicate.User) predicate.SkipEdgeExample { // And groups predicates with the AND operator between them. func And(predicates ...predicate.SkipEdgeExample) predicate.SkipEdgeExample { - return predicate.SkipEdgeExample(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.SkipEdgeExample(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.SkipEdgeExample) predicate.SkipEdgeExample { - return predicate.SkipEdgeExample(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.SkipEdgeExample(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.SkipEdgeExample) predicate.SkipEdgeExample { - return predicate.SkipEdgeExample(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.SkipEdgeExample(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/skipedgeexample_create.go b/entproto/internal/todo/ent/skipedgeexample_create.go index 1d6a986c7..adfe1b090 100644 --- a/entproto/internal/todo/ent/skipedgeexample_create.go +++ b/entproto/internal/todo/ent/skipedgeexample_create.go @@ -45,7 +45,7 @@ func (seec *SkipEdgeExampleCreate) Mutation() *SkipEdgeExampleMutation { // Save creates the SkipEdgeExample in the database. func (seec *SkipEdgeExampleCreate) Save(ctx context.Context) (*SkipEdgeExample, error) { - return withHooks[*SkipEdgeExample, SkipEdgeExampleMutation](ctx, seec.sqlSave, seec.mutation, seec.hooks) + return withHooks(ctx, seec.sqlSave, seec.mutation, seec.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -121,11 +121,15 @@ func (seec *SkipEdgeExampleCreate) createSpec() (*SkipEdgeExample, *sqlgraph.Cre // SkipEdgeExampleCreateBulk is the builder for creating many SkipEdgeExample entities in bulk. type SkipEdgeExampleCreateBulk struct { config + err error builders []*SkipEdgeExampleCreate } // Save creates the SkipEdgeExample entities in the database. func (seecb *SkipEdgeExampleCreateBulk) Save(ctx context.Context) ([]*SkipEdgeExample, error) { + if seecb.err != nil { + return nil, seecb.err + } specs := make([]*sqlgraph.CreateSpec, len(seecb.builders)) nodes := make([]*SkipEdgeExample, len(seecb.builders)) mutators := make([]Mutator, len(seecb.builders)) diff --git a/entproto/internal/todo/ent/skipedgeexample_delete.go b/entproto/internal/todo/ent/skipedgeexample_delete.go index c784a8338..a31a9f3a7 100644 --- a/entproto/internal/todo/ent/skipedgeexample_delete.go +++ b/entproto/internal/todo/ent/skipedgeexample_delete.go @@ -27,7 +27,7 @@ func (seed *SkipEdgeExampleDelete) Where(ps ...predicate.SkipEdgeExample) *SkipE // Exec executes the deletion query and returns how many vertices were deleted. func (seed *SkipEdgeExampleDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, SkipEdgeExampleMutation](ctx, seed.sqlExec, seed.mutation, seed.hooks) + return withHooks(ctx, seed.sqlExec, seed.mutation, seed.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/skipedgeexample_update.go b/entproto/internal/todo/ent/skipedgeexample_update.go index f43713b87..824bf4f49 100644 --- a/entproto/internal/todo/ent/skipedgeexample_update.go +++ b/entproto/internal/todo/ent/skipedgeexample_update.go @@ -60,7 +60,7 @@ func (seeu *SkipEdgeExampleUpdate) ClearUser() *SkipEdgeExampleUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (seeu *SkipEdgeExampleUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, SkipEdgeExampleMutation](ctx, seeu.sqlSave, seeu.mutation, seeu.hooks) + return withHooks(ctx, seeu.sqlSave, seeu.mutation, seeu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -188,7 +188,7 @@ func (seeuo *SkipEdgeExampleUpdateOne) Select(field string, fields ...string) *S // Save executes the query and returns the updated SkipEdgeExample entity. func (seeuo *SkipEdgeExampleUpdateOne) Save(ctx context.Context) (*SkipEdgeExample, error) { - return withHooks[*SkipEdgeExample, SkipEdgeExampleMutation](ctx, seeuo.sqlSave, seeuo.mutation, seeuo.hooks) + return withHooks(ctx, seeuo.sqlSave, seeuo.mutation, seeuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/todo/where.go b/entproto/internal/todo/ent/todo/where.go index b34244127..e76f749b7 100644 --- a/entproto/internal/todo/ent/todo/where.go +++ b/entproto/internal/todo/ent/todo/where.go @@ -168,32 +168,15 @@ func HasUserWith(preds ...predicate.User) predicate.Todo { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Todo(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Todo) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Todo(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/todo_create.go b/entproto/internal/todo/ent/todo_create.go index 03635c67f..60f4c6f08 100644 --- a/entproto/internal/todo/ent/todo_create.go +++ b/entproto/internal/todo/ent/todo_create.go @@ -67,7 +67,7 @@ func (tc *TodoCreate) Mutation() *TodoMutation { // Save creates the Todo in the database. func (tc *TodoCreate) Save(ctx context.Context) (*Todo, error) { tc.defaults() - return withHooks[*Todo, TodoMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -170,11 +170,15 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { // TodoCreateBulk is the builder for creating many Todo entities in bulk. type TodoCreateBulk struct { config + err error builders []*TodoCreate } // Save creates the Todo entities in the database. func (tcb *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Todo, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) diff --git a/entproto/internal/todo/ent/todo_delete.go b/entproto/internal/todo/ent/todo_delete.go index 3fb769136..f827e7504 100644 --- a/entproto/internal/todo/ent/todo_delete.go +++ b/entproto/internal/todo/ent/todo_delete.go @@ -27,7 +27,7 @@ func (td *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TodoDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/todo_update.go b/entproto/internal/todo/ent/todo_update.go index b360cc55f..13b6f4712 100644 --- a/entproto/internal/todo/ent/todo_update.go +++ b/entproto/internal/todo/ent/todo_update.go @@ -34,6 +34,14 @@ func (tu *TodoUpdate) SetTask(s string) *TodoUpdate { return tu } +// SetNillableTask sets the "task" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableTask(s *string) *TodoUpdate { + if s != nil { + tu.SetTask(*s) + } + return tu +} + // SetStatus sets the "status" field. func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate { tu.mutation.SetStatus(t) @@ -80,7 +88,7 @@ func (tu *TodoUpdate) ClearUser() *TodoUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TodoUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TodoMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -188,6 +196,14 @@ func (tuo *TodoUpdateOne) SetTask(s string) *TodoUpdateOne { return tuo } +// SetNillableTask sets the "task" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableTask(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetTask(*s) + } + return tuo +} + // SetStatus sets the "status" field. func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne { tuo.mutation.SetStatus(t) @@ -247,7 +263,7 @@ func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne // Save executes the query and returns the updated Todo entity. func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { - return withHooks[*Todo, TodoMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/user/where.go b/entproto/internal/todo/ent/user/where.go index 6a258a35d..bbcfe58eb 100644 --- a/entproto/internal/todo/ent/user/where.go +++ b/entproto/internal/todo/ent/user/where.go @@ -1179,32 +1179,15 @@ func HasSkipEdgeWith(preds ...predicate.SkipEdgeExample) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/entproto/internal/todo/ent/user_create.go b/entproto/internal/todo/ent/user_create.go index bd1f6d225..8c67b5f79 100644 --- a/entproto/internal/todo/ent/user_create.go +++ b/entproto/internal/todo/ent/user_create.go @@ -375,7 +375,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { uc.defaults() - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -707,11 +707,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/entproto/internal/todo/ent/user_delete.go b/entproto/internal/todo/ent/user_delete.go index 82497218c..93a6d3a0f 100644 --- a/entproto/internal/todo/ent/user_delete.go +++ b/entproto/internal/todo/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/entproto/internal/todo/ent/user_update.go b/entproto/internal/todo/ent/user_update.go index af07443d4..84f9d38cc 100644 --- a/entproto/internal/todo/ent/user_update.go +++ b/entproto/internal/todo/ent/user_update.go @@ -40,6 +40,14 @@ func (uu *UserUpdate) SetUserName(s string) *UserUpdate { return uu } +// SetNillableUserName sets the "user_name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableUserName(s *string) *UserUpdate { + if s != nil { + uu.SetUserName(*s) + } + return uu +} + // SetPoints sets the "points" field. func (uu *UserUpdate) SetPoints(u uint) *UserUpdate { uu.mutation.ResetPoints() @@ -47,6 +55,14 @@ func (uu *UserUpdate) SetPoints(u uint) *UserUpdate { return uu } +// SetNillablePoints sets the "points" field if the given value is not nil. +func (uu *UserUpdate) SetNillablePoints(u *uint) *UserUpdate { + if u != nil { + uu.SetPoints(*u) + } + return uu +} + // AddPoints adds u to the "points" field. func (uu *UserUpdate) AddPoints(u int) *UserUpdate { uu.mutation.AddPoints(u) @@ -60,6 +76,14 @@ func (uu *UserUpdate) SetExp(u uint64) *UserUpdate { return uu } +// SetNillableExp sets the "exp" field if the given value is not nil. +func (uu *UserUpdate) SetNillableExp(u *uint64) *UserUpdate { + if u != nil { + uu.SetExp(*u) + } + return uu +} + // AddExp adds u to the "exp" field. func (uu *UserUpdate) AddExp(u int64) *UserUpdate { uu.mutation.AddExp(u) @@ -72,6 +96,14 @@ func (uu *UserUpdate) SetStatus(u user.Status) *UserUpdate { return uu } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (uu *UserUpdate) SetNillableStatus(u *user.Status) *UserUpdate { + if u != nil { + uu.SetStatus(*u) + } + return uu +} + // SetExternalID sets the "external_id" field. func (uu *UserUpdate) SetExternalID(i int) *UserUpdate { uu.mutation.ResetExternalID() @@ -79,6 +111,14 @@ func (uu *UserUpdate) SetExternalID(i int) *UserUpdate { return uu } +// SetNillableExternalID sets the "external_id" field if the given value is not nil. +func (uu *UserUpdate) SetNillableExternalID(i *int) *UserUpdate { + if i != nil { + uu.SetExternalID(*i) + } + return uu +} + // AddExternalID adds i to the "external_id" field. func (uu *UserUpdate) AddExternalID(i int) *UserUpdate { uu.mutation.AddExternalID(i) @@ -91,6 +131,14 @@ func (uu *UserUpdate) SetCrmID(u uuid.UUID) *UserUpdate { return uu } +// SetNillableCrmID sets the "crm_id" field if the given value is not nil. +func (uu *UserUpdate) SetNillableCrmID(u *uuid.UUID) *UserUpdate { + if u != nil { + uu.SetCrmID(*u) + } + return uu +} + // SetBanned sets the "banned" field. func (uu *UserUpdate) SetBanned(b bool) *UserUpdate { uu.mutation.SetBanned(b) @@ -112,6 +160,14 @@ func (uu *UserUpdate) SetCustomPb(u uint8) *UserUpdate { return uu } +// SetNillableCustomPb sets the "custom_pb" field if the given value is not nil. +func (uu *UserUpdate) SetNillableCustomPb(u *uint8) *UserUpdate { + if u != nil { + uu.SetCustomPb(*u) + } + return uu +} + // AddCustomPb adds u to the "custom_pb" field. func (uu *UserUpdate) AddCustomPb(u int8) *UserUpdate { uu.mutation.AddCustomPb(u) @@ -424,12 +480,28 @@ func (uu *UserUpdate) SetOmitPrefix(up user.OmitPrefix) *UserUpdate { return uu } +// SetNillableOmitPrefix sets the "omit_prefix" field if the given value is not nil. +func (uu *UserUpdate) SetNillableOmitPrefix(up *user.OmitPrefix) *UserUpdate { + if up != nil { + uu.SetOmitPrefix(*up) + } + return uu +} + // SetMimeType sets the "mime_type" field. func (uu *UserUpdate) SetMimeType(ut user.MimeType) *UserUpdate { uu.mutation.SetMimeType(ut) return uu } +// SetNillableMimeType sets the "mime_type" field if the given value is not nil. +func (uu *UserUpdate) SetNillableMimeType(ut *user.MimeType) *UserUpdate { + if ut != nil { + uu.SetMimeType(*ut) + } + return uu +} + // SetGroupID sets the "group" edge to the Group entity by ID. func (uu *UserUpdate) SetGroupID(id int) *UserUpdate { uu.mutation.SetGroupID(id) @@ -573,7 +645,7 @@ func (uu *UserUpdate) ClearSkipEdge() *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -982,6 +1054,14 @@ func (uuo *UserUpdateOne) SetUserName(s string) *UserUpdateOne { return uuo } +// SetNillableUserName sets the "user_name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableUserName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetUserName(*s) + } + return uuo +} + // SetPoints sets the "points" field. func (uuo *UserUpdateOne) SetPoints(u uint) *UserUpdateOne { uuo.mutation.ResetPoints() @@ -989,6 +1069,14 @@ func (uuo *UserUpdateOne) SetPoints(u uint) *UserUpdateOne { return uuo } +// SetNillablePoints sets the "points" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillablePoints(u *uint) *UserUpdateOne { + if u != nil { + uuo.SetPoints(*u) + } + return uuo +} + // AddPoints adds u to the "points" field. func (uuo *UserUpdateOne) AddPoints(u int) *UserUpdateOne { uuo.mutation.AddPoints(u) @@ -1002,6 +1090,14 @@ func (uuo *UserUpdateOne) SetExp(u uint64) *UserUpdateOne { return uuo } +// SetNillableExp sets the "exp" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableExp(u *uint64) *UserUpdateOne { + if u != nil { + uuo.SetExp(*u) + } + return uuo +} + // AddExp adds u to the "exp" field. func (uuo *UserUpdateOne) AddExp(u int64) *UserUpdateOne { uuo.mutation.AddExp(u) @@ -1014,6 +1110,14 @@ func (uuo *UserUpdateOne) SetStatus(u user.Status) *UserUpdateOne { return uuo } +// SetNillableStatus sets the "status" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableStatus(u *user.Status) *UserUpdateOne { + if u != nil { + uuo.SetStatus(*u) + } + return uuo +} + // SetExternalID sets the "external_id" field. func (uuo *UserUpdateOne) SetExternalID(i int) *UserUpdateOne { uuo.mutation.ResetExternalID() @@ -1021,6 +1125,14 @@ func (uuo *UserUpdateOne) SetExternalID(i int) *UserUpdateOne { return uuo } +// SetNillableExternalID sets the "external_id" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableExternalID(i *int) *UserUpdateOne { + if i != nil { + uuo.SetExternalID(*i) + } + return uuo +} + // AddExternalID adds i to the "external_id" field. func (uuo *UserUpdateOne) AddExternalID(i int) *UserUpdateOne { uuo.mutation.AddExternalID(i) @@ -1033,6 +1145,14 @@ func (uuo *UserUpdateOne) SetCrmID(u uuid.UUID) *UserUpdateOne { return uuo } +// SetNillableCrmID sets the "crm_id" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableCrmID(u *uuid.UUID) *UserUpdateOne { + if u != nil { + uuo.SetCrmID(*u) + } + return uuo +} + // SetBanned sets the "banned" field. func (uuo *UserUpdateOne) SetBanned(b bool) *UserUpdateOne { uuo.mutation.SetBanned(b) @@ -1054,6 +1174,14 @@ func (uuo *UserUpdateOne) SetCustomPb(u uint8) *UserUpdateOne { return uuo } +// SetNillableCustomPb sets the "custom_pb" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableCustomPb(u *uint8) *UserUpdateOne { + if u != nil { + uuo.SetCustomPb(*u) + } + return uuo +} + // AddCustomPb adds u to the "custom_pb" field. func (uuo *UserUpdateOne) AddCustomPb(u int8) *UserUpdateOne { uuo.mutation.AddCustomPb(u) @@ -1366,12 +1494,28 @@ func (uuo *UserUpdateOne) SetOmitPrefix(up user.OmitPrefix) *UserUpdateOne { return uuo } +// SetNillableOmitPrefix sets the "omit_prefix" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableOmitPrefix(up *user.OmitPrefix) *UserUpdateOne { + if up != nil { + uuo.SetOmitPrefix(*up) + } + return uuo +} + // SetMimeType sets the "mime_type" field. func (uuo *UserUpdateOne) SetMimeType(ut user.MimeType) *UserUpdateOne { uuo.mutation.SetMimeType(ut) return uuo } +// SetNillableMimeType sets the "mime_type" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableMimeType(ut *user.MimeType) *UserUpdateOne { + if ut != nil { + uuo.SetMimeType(*ut) + } + return uuo +} + // SetGroupID sets the "group" edge to the Group entity by ID. func (uuo *UserUpdateOne) SetGroupID(id int) *UserUpdateOne { uuo.mutation.SetGroupID(id) @@ -1528,7 +1672,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/entproto/internal/todo/generate_test.go b/entproto/internal/todo/generate_test.go index 40ac70dd5..31e918221 100644 --- a/entproto/internal/todo/generate_test.go +++ b/entproto/internal/todo/generate_test.go @@ -44,7 +44,7 @@ func TestGenerate(t *testing.T) { func TestGenerateOptionSkipGenFile(t *testing.T) { tgt := t.TempDir() - entprotoExt,err := entproto.NewExtension(entproto.SkipGenFile()) + entprotoExt, err := entproto.NewExtension(entproto.SkipGenFile()) require.NoError(t, err) err = entc.Generate( diff --git a/go.mod b/go.mod index 0ebce8869..fc7021bc4 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module entgo.io/contrib -go 1.18 +go 1.20 require ( - entgo.io/ent v0.12.2 + entgo.io/ent v0.12.5-0.20231110085726-c2ff3ff3bca9 github.com/99designs/gqlgen v0.17.36 github.com/AlekSi/pointer v1.1.0 github.com/alecthomas/kong v0.7.0 @@ -29,7 +29,7 @@ require ( ) require ( - ariga.io/atlas v0.10.0 // indirect + ariga.io/atlas v0.15.1-0.20231110144547-3e8e2e192e6b // indirect github.com/agext/levenshtein v1.2.1 // indirect github.com/agnivade/levenshtein v1.1.1 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect diff --git a/go.sum b/go.sum index bf2dc28cb..06777c81d 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ -ariga.io/atlas v0.10.0 h1:B1aCP6gSDQET6j8ybn7m6MArjQuoLH5d4DQBT+NP5k8= -ariga.io/atlas v0.10.0/go.mod h1:+TR129FJZ5Lvzms6dvCeGWh1yR6hMvmXBhug4hrNIGk= +ariga.io/atlas v0.15.1-0.20231110144547-3e8e2e192e6b h1:LuwxCerCP0veSXGIaGojzETOnAsdoO97GJaLUInAQGc= +ariga.io/atlas v0.15.1-0.20231110144547-3e8e2e192e6b/go.mod h1:isZrlzJ5cpoCoKFoY9knZug7Lq4pP1cm8g3XciLZ0Pw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -entgo.io/ent v0.12.2 h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM= -entgo.io/ent v0.12.2/go.mod h1:OA1Y5bNE8EtlxKv4IyzWwt4jgvGbkoKMcwp668iEKQE= +entgo.io/ent v0.12.5-0.20231110085726-c2ff3ff3bca9 h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE= +entgo.io/ent v0.12.5-0.20231110085726-c2ff3ff3bca9/go.mod h1:Y3JVAjtlIk8xVZYSn3t3mf8xlZIn5SAOXZQxD6kKI+Q= github.com/99designs/gqlgen v0.17.36 h1:u/o/rv2SZ9s5280dyUOOrkpIIkr/7kITMXYD3rkJ9go= github.com/99designs/gqlgen v0.17.36/go.mod h1:6RdyY8puhCoWAQVr2qzF2OMVfudQzc8ACxzpzluoQm4= github.com/AlekSi/pointer v1.1.0 h1:SSDMPcXD9jSl8FPy9cRzoRaMJtm9g9ggGTxecRUbQoI= diff --git a/schemast/internal/loadtest/ent/client.go b/schemast/internal/loadtest/ent/client.go index 72b5f8798..ef29e1a41 100644 --- a/schemast/internal/loadtest/ent/client.go +++ b/schemast/internal/loadtest/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/schemast/internal/loadtest/ent/migrate" "entgo.io/ent" @@ -104,11 +105,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -220,6 +224,21 @@ func (c *MessageClient) CreateBulk(builders ...*MessageCreate) *MessageCreateBul return &MessageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageClient) MapCreateBulk(slice any, setFunc func(*MessageCreate, int)) *MessageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageCreateBulk{err: fmt.Errorf("calling to MessageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Message. func (c *MessageClient) Update() *MessageUpdate { mutation := newMessageMutation(c.config, OpUpdate) diff --git a/schemast/internal/loadtest/ent/message/where.go b/schemast/internal/loadtest/ent/message/where.go index c67db20d9..ad4c0585f 100644 --- a/schemast/internal/loadtest/ent/message/where.go +++ b/schemast/internal/loadtest/ent/message/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.Message { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Message) predicate.Message { - return predicate.Message(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Message(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Message) predicate.Message { - return predicate.Message(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Message(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Message) predicate.Message { - return predicate.Message(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Message(sql.NotPredicates(p)) } diff --git a/schemast/internal/loadtest/ent/message_create.go b/schemast/internal/loadtest/ent/message_create.go index d8aec0497..7be2f1977 100644 --- a/schemast/internal/loadtest/ent/message_create.go +++ b/schemast/internal/loadtest/ent/message_create.go @@ -25,7 +25,7 @@ func (mc *MessageCreate) Mutation() *MessageMutation { // Save creates the Message in the database. func (mc *MessageCreate) Save(ctx context.Context) (*Message, error) { - return withHooks[*Message, MessageMutation](ctx, mc.sqlSave, mc.mutation, mc.hooks) + return withHooks(ctx, mc.sqlSave, mc.mutation, mc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (mc *MessageCreate) createSpec() (*Message, *sqlgraph.CreateSpec) { // MessageCreateBulk is the builder for creating many Message entities in bulk. type MessageCreateBulk struct { config + err error builders []*MessageCreate } // Save creates the Message entities in the database. func (mcb *MessageCreateBulk) Save(ctx context.Context) ([]*Message, error) { + if mcb.err != nil { + return nil, mcb.err + } specs := make([]*sqlgraph.CreateSpec, len(mcb.builders)) nodes := make([]*Message, len(mcb.builders)) mutators := make([]Mutator, len(mcb.builders)) diff --git a/schemast/internal/loadtest/ent/message_delete.go b/schemast/internal/loadtest/ent/message_delete.go index c585b787b..97c9bd74f 100644 --- a/schemast/internal/loadtest/ent/message_delete.go +++ b/schemast/internal/loadtest/ent/message_delete.go @@ -27,7 +27,7 @@ func (md *MessageDelete) Where(ps ...predicate.Message) *MessageDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (md *MessageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageMutation](ctx, md.sqlExec, md.mutation, md.hooks) + return withHooks(ctx, md.sqlExec, md.mutation, md.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/loadtest/ent/message_update.go b/schemast/internal/loadtest/ent/message_update.go index a8a7d42a5..4e1c1e523 100644 --- a/schemast/internal/loadtest/ent/message_update.go +++ b/schemast/internal/loadtest/ent/message_update.go @@ -34,7 +34,7 @@ func (mu *MessageUpdate) Mutation() *MessageMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (mu *MessageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageMutation](ctx, mu.sqlSave, mu.mutation, mu.hooks) + return withHooks(ctx, mu.sqlSave, mu.mutation, mu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (muo *MessageUpdateOne) Select(field string, fields ...string) *MessageUpda // Save executes the query and returns the updated Message entity. func (muo *MessageUpdateOne) Save(ctx context.Context) (*Message, error) { - return withHooks[*Message, MessageMutation](ctx, muo.sqlSave, muo.mutation, muo.hooks) + return withHooks(ctx, muo.sqlSave, muo.mutation, muo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/schemast/internal/loadtest/ent/runtime/runtime.go b/schemast/internal/loadtest/ent/runtime/runtime.go index 2664987df..fd1d620a8 100644 --- a/schemast/internal/loadtest/ent/runtime/runtime.go +++ b/schemast/internal/loadtest/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/schemast/internal/loadtest/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/schemast/internal/mutatetest/ent/client.go b/schemast/internal/mutatetest/ent/client.go index d992c65e4..8ffcabd2c 100644 --- a/schemast/internal/mutatetest/ent/client.go +++ b/schemast/internal/mutatetest/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/schemast/internal/mutatetest/ent/migrate" "entgo.io/ent" @@ -121,11 +122,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -261,6 +265,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) @@ -379,6 +398,21 @@ func (c *WithFieldsClient) CreateBulk(builders ...*WithFieldsCreate) *WithFields return &WithFieldsCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *WithFieldsClient) MapCreateBulk(slice any, setFunc func(*WithFieldsCreate, int)) *WithFieldsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &WithFieldsCreateBulk{err: fmt.Errorf("calling to WithFieldsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*WithFieldsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &WithFieldsCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for WithFields. func (c *WithFieldsClient) Update() *WithFieldsUpdate { mutation := newWithFieldsMutation(c.config, OpUpdate) @@ -497,6 +531,21 @@ func (c *WithModifiedFieldClient) CreateBulk(builders ...*WithModifiedFieldCreat return &WithModifiedFieldCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *WithModifiedFieldClient) MapCreateBulk(slice any, setFunc func(*WithModifiedFieldCreate, int)) *WithModifiedFieldCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &WithModifiedFieldCreateBulk{err: fmt.Errorf("calling to WithModifiedFieldClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*WithModifiedFieldCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &WithModifiedFieldCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for WithModifiedField. func (c *WithModifiedFieldClient) Update() *WithModifiedFieldUpdate { mutation := newWithModifiedFieldMutation(c.config, OpUpdate) @@ -631,6 +680,21 @@ func (c *WithNilFieldsClient) CreateBulk(builders ...*WithNilFieldsCreate) *With return &WithNilFieldsCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *WithNilFieldsClient) MapCreateBulk(slice any, setFunc func(*WithNilFieldsCreate, int)) *WithNilFieldsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &WithNilFieldsCreateBulk{err: fmt.Errorf("calling to WithNilFieldsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*WithNilFieldsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &WithNilFieldsCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for WithNilFields. func (c *WithNilFieldsClient) Update() *WithNilFieldsUpdate { mutation := newWithNilFieldsMutation(c.config, OpUpdate) @@ -749,6 +813,21 @@ func (c *WithoutFieldsClient) CreateBulk(builders ...*WithoutFieldsCreate) *With return &WithoutFieldsCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *WithoutFieldsClient) MapCreateBulk(slice any, setFunc func(*WithoutFieldsCreate, int)) *WithoutFieldsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &WithoutFieldsCreateBulk{err: fmt.Errorf("calling to WithoutFieldsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*WithoutFieldsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &WithoutFieldsCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for WithoutFields. func (c *WithoutFieldsClient) Update() *WithoutFieldsUpdate { mutation := newWithoutFieldsMutation(c.config, OpUpdate) diff --git a/schemast/internal/mutatetest/ent/runtime/runtime.go b/schemast/internal/mutatetest/ent/runtime/runtime.go index b31a36a87..90ead650a 100644 --- a/schemast/internal/mutatetest/ent/runtime/runtime.go +++ b/schemast/internal/mutatetest/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/schemast/internal/mutatetest/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/schemast/internal/mutatetest/ent/user/where.go b/schemast/internal/mutatetest/ent/user/where.go index 41d2d93a1..96bcf60e2 100644 --- a/schemast/internal/mutatetest/ent/user/where.go +++ b/schemast/internal/mutatetest/ent/user/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/schemast/internal/mutatetest/ent/user_create.go b/schemast/internal/mutatetest/ent/user_create.go index 38548ca76..61499e0dd 100644 --- a/schemast/internal/mutatetest/ent/user_create.go +++ b/schemast/internal/mutatetest/ent/user_create.go @@ -25,7 +25,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/schemast/internal/mutatetest/ent/user_delete.go b/schemast/internal/mutatetest/ent/user_delete.go index 6c6e11afc..da0b9db5d 100644 --- a/schemast/internal/mutatetest/ent/user_delete.go +++ b/schemast/internal/mutatetest/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/user_update.go b/schemast/internal/mutatetest/ent/user_update.go index b954088ac..74e80e469 100644 --- a/schemast/internal/mutatetest/ent/user_update.go +++ b/schemast/internal/mutatetest/ent/user_update.go @@ -34,7 +34,7 @@ func (uu *UserUpdate) Mutation() *UserMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withfields/where.go b/schemast/internal/mutatetest/ent/withfields/where.go index 2348ac05b..dbb2bc620 100644 --- a/schemast/internal/mutatetest/ent/withfields/where.go +++ b/schemast/internal/mutatetest/ent/withfields/where.go @@ -124,32 +124,15 @@ func ExistingContainsFold(v string) predicate.WithFields { // And groups predicates with the AND operator between them. func And(predicates ...predicate.WithFields) predicate.WithFields { - return predicate.WithFields(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithFields(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.WithFields) predicate.WithFields { - return predicate.WithFields(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithFields(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.WithFields) predicate.WithFields { - return predicate.WithFields(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.WithFields(sql.NotPredicates(p)) } diff --git a/schemast/internal/mutatetest/ent/withfields_create.go b/schemast/internal/mutatetest/ent/withfields_create.go index f025174cc..01bcae22d 100644 --- a/schemast/internal/mutatetest/ent/withfields_create.go +++ b/schemast/internal/mutatetest/ent/withfields_create.go @@ -32,7 +32,7 @@ func (wfc *WithFieldsCreate) Mutation() *WithFieldsMutation { // Save creates the WithFields in the database. func (wfc *WithFieldsCreate) Save(ctx context.Context) (*WithFields, error) { - return withHooks[*WithFields, WithFieldsMutation](ctx, wfc.sqlSave, wfc.mutation, wfc.hooks) + return withHooks(ctx, wfc.sqlSave, wfc.mutation, wfc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -98,11 +98,15 @@ func (wfc *WithFieldsCreate) createSpec() (*WithFields, *sqlgraph.CreateSpec) { // WithFieldsCreateBulk is the builder for creating many WithFields entities in bulk. type WithFieldsCreateBulk struct { config + err error builders []*WithFieldsCreate } // Save creates the WithFields entities in the database. func (wfcb *WithFieldsCreateBulk) Save(ctx context.Context) ([]*WithFields, error) { + if wfcb.err != nil { + return nil, wfcb.err + } specs := make([]*sqlgraph.CreateSpec, len(wfcb.builders)) nodes := make([]*WithFields, len(wfcb.builders)) mutators := make([]Mutator, len(wfcb.builders)) diff --git a/schemast/internal/mutatetest/ent/withfields_delete.go b/schemast/internal/mutatetest/ent/withfields_delete.go index 4a9bfde2b..3cc4e01cc 100644 --- a/schemast/internal/mutatetest/ent/withfields_delete.go +++ b/schemast/internal/mutatetest/ent/withfields_delete.go @@ -27,7 +27,7 @@ func (wfd *WithFieldsDelete) Where(ps ...predicate.WithFields) *WithFieldsDelete // Exec executes the deletion query and returns how many vertices were deleted. func (wfd *WithFieldsDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, WithFieldsMutation](ctx, wfd.sqlExec, wfd.mutation, wfd.hooks) + return withHooks(ctx, wfd.sqlExec, wfd.mutation, wfd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withfields_update.go b/schemast/internal/mutatetest/ent/withfields_update.go index 4c6138c02..d70b161a5 100644 --- a/schemast/internal/mutatetest/ent/withfields_update.go +++ b/schemast/internal/mutatetest/ent/withfields_update.go @@ -33,6 +33,14 @@ func (wfu *WithFieldsUpdate) SetExisting(s string) *WithFieldsUpdate { return wfu } +// SetNillableExisting sets the "existing" field if the given value is not nil. +func (wfu *WithFieldsUpdate) SetNillableExisting(s *string) *WithFieldsUpdate { + if s != nil { + wfu.SetExisting(*s) + } + return wfu +} + // Mutation returns the WithFieldsMutation object of the builder. func (wfu *WithFieldsUpdate) Mutation() *WithFieldsMutation { return wfu.mutation @@ -40,7 +48,7 @@ func (wfu *WithFieldsUpdate) Mutation() *WithFieldsMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (wfu *WithFieldsUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, WithFieldsMutation](ctx, wfu.sqlSave, wfu.mutation, wfu.hooks) + return withHooks(ctx, wfu.sqlSave, wfu.mutation, wfu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -103,6 +111,14 @@ func (wfuo *WithFieldsUpdateOne) SetExisting(s string) *WithFieldsUpdateOne { return wfuo } +// SetNillableExisting sets the "existing" field if the given value is not nil. +func (wfuo *WithFieldsUpdateOne) SetNillableExisting(s *string) *WithFieldsUpdateOne { + if s != nil { + wfuo.SetExisting(*s) + } + return wfuo +} + // Mutation returns the WithFieldsMutation object of the builder. func (wfuo *WithFieldsUpdateOne) Mutation() *WithFieldsMutation { return wfuo.mutation @@ -123,7 +139,7 @@ func (wfuo *WithFieldsUpdateOne) Select(field string, fields ...string) *WithFie // Save executes the query and returns the updated WithFields entity. func (wfuo *WithFieldsUpdateOne) Save(ctx context.Context) (*WithFields, error) { - return withHooks[*WithFields, WithFieldsMutation](ctx, wfuo.sqlSave, wfuo.mutation, wfuo.hooks) + return withHooks(ctx, wfuo.sqlSave, wfuo.mutation, wfuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withmodifiedfield/where.go b/schemast/internal/mutatetest/ent/withmodifiedfield/where.go index 19212d953..c909d1fec 100644 --- a/schemast/internal/mutatetest/ent/withmodifiedfield/where.go +++ b/schemast/internal/mutatetest/ent/withmodifiedfield/where.go @@ -148,32 +148,15 @@ func HasOwnerWith(preds ...predicate.User) predicate.WithModifiedField { // And groups predicates with the AND operator between them. func And(predicates ...predicate.WithModifiedField) predicate.WithModifiedField { - return predicate.WithModifiedField(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithModifiedField(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.WithModifiedField) predicate.WithModifiedField { - return predicate.WithModifiedField(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithModifiedField(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.WithModifiedField) predicate.WithModifiedField { - return predicate.WithModifiedField(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.WithModifiedField(sql.NotPredicates(p)) } diff --git a/schemast/internal/mutatetest/ent/withmodifiedfield_create.go b/schemast/internal/mutatetest/ent/withmodifiedfield_create.go index e748a31b0..4a8bd43cb 100644 --- a/schemast/internal/mutatetest/ent/withmodifiedfield_create.go +++ b/schemast/internal/mutatetest/ent/withmodifiedfield_create.go @@ -52,7 +52,7 @@ func (wmfc *WithModifiedFieldCreate) Mutation() *WithModifiedFieldMutation { // Save creates the WithModifiedField in the database. func (wmfc *WithModifiedFieldCreate) Save(ctx context.Context) (*WithModifiedField, error) { - return withHooks[*WithModifiedField, WithModifiedFieldMutation](ctx, wmfc.sqlSave, wmfc.mutation, wmfc.hooks) + return withHooks(ctx, wmfc.sqlSave, wmfc.mutation, wmfc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -140,11 +140,15 @@ func (wmfc *WithModifiedFieldCreate) createSpec() (*WithModifiedField, *sqlgraph // WithModifiedFieldCreateBulk is the builder for creating many WithModifiedField entities in bulk. type WithModifiedFieldCreateBulk struct { config + err error builders []*WithModifiedFieldCreate } // Save creates the WithModifiedField entities in the database. func (wmfcb *WithModifiedFieldCreateBulk) Save(ctx context.Context) ([]*WithModifiedField, error) { + if wmfcb.err != nil { + return nil, wmfcb.err + } specs := make([]*sqlgraph.CreateSpec, len(wmfcb.builders)) nodes := make([]*WithModifiedField, len(wmfcb.builders)) mutators := make([]Mutator, len(wmfcb.builders)) diff --git a/schemast/internal/mutatetest/ent/withmodifiedfield_delete.go b/schemast/internal/mutatetest/ent/withmodifiedfield_delete.go index 07dca7c72..c09ce2811 100644 --- a/schemast/internal/mutatetest/ent/withmodifiedfield_delete.go +++ b/schemast/internal/mutatetest/ent/withmodifiedfield_delete.go @@ -27,7 +27,7 @@ func (wmfd *WithModifiedFieldDelete) Where(ps ...predicate.WithModifiedField) *W // Exec executes the deletion query and returns how many vertices were deleted. func (wmfd *WithModifiedFieldDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, WithModifiedFieldMutation](ctx, wmfd.sqlExec, wmfd.mutation, wmfd.hooks) + return withHooks(ctx, wmfd.sqlExec, wmfd.mutation, wmfd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withmodifiedfield_update.go b/schemast/internal/mutatetest/ent/withmodifiedfield_update.go index 4c0838950..255c98234 100644 --- a/schemast/internal/mutatetest/ent/withmodifiedfield_update.go +++ b/schemast/internal/mutatetest/ent/withmodifiedfield_update.go @@ -60,7 +60,7 @@ func (wmfu *WithModifiedFieldUpdate) ClearOwner() *WithModifiedFieldUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (wmfu *WithModifiedFieldUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, WithModifiedFieldMutation](ctx, wmfu.sqlSave, wmfu.mutation, wmfu.hooks) + return withHooks(ctx, wmfu.sqlSave, wmfu.mutation, wmfu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -188,7 +188,7 @@ func (wmfuo *WithModifiedFieldUpdateOne) Select(field string, fields ...string) // Save executes the query and returns the updated WithModifiedField entity. func (wmfuo *WithModifiedFieldUpdateOne) Save(ctx context.Context) (*WithModifiedField, error) { - return withHooks[*WithModifiedField, WithModifiedFieldMutation](ctx, wmfuo.sqlSave, wmfuo.mutation, wmfuo.hooks) + return withHooks(ctx, wmfuo.sqlSave, wmfuo.mutation, wmfuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withnilfields/where.go b/schemast/internal/mutatetest/ent/withnilfields/where.go index 7f7d0fde5..34d02efa0 100644 --- a/schemast/internal/mutatetest/ent/withnilfields/where.go +++ b/schemast/internal/mutatetest/ent/withnilfields/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.WithNilFields { // And groups predicates with the AND operator between them. func And(predicates ...predicate.WithNilFields) predicate.WithNilFields { - return predicate.WithNilFields(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithNilFields(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.WithNilFields) predicate.WithNilFields { - return predicate.WithNilFields(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithNilFields(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.WithNilFields) predicate.WithNilFields { - return predicate.WithNilFields(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.WithNilFields(sql.NotPredicates(p)) } diff --git a/schemast/internal/mutatetest/ent/withnilfields_create.go b/schemast/internal/mutatetest/ent/withnilfields_create.go index fd22f1207..b2150ab89 100644 --- a/schemast/internal/mutatetest/ent/withnilfields_create.go +++ b/schemast/internal/mutatetest/ent/withnilfields_create.go @@ -25,7 +25,7 @@ func (wnfc *WithNilFieldsCreate) Mutation() *WithNilFieldsMutation { // Save creates the WithNilFields in the database. func (wnfc *WithNilFieldsCreate) Save(ctx context.Context) (*WithNilFields, error) { - return withHooks[*WithNilFields, WithNilFieldsMutation](ctx, wnfc.sqlSave, wnfc.mutation, wnfc.hooks) + return withHooks(ctx, wnfc.sqlSave, wnfc.mutation, wnfc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (wnfc *WithNilFieldsCreate) createSpec() (*WithNilFields, *sqlgraph.CreateS // WithNilFieldsCreateBulk is the builder for creating many WithNilFields entities in bulk. type WithNilFieldsCreateBulk struct { config + err error builders []*WithNilFieldsCreate } // Save creates the WithNilFields entities in the database. func (wnfcb *WithNilFieldsCreateBulk) Save(ctx context.Context) ([]*WithNilFields, error) { + if wnfcb.err != nil { + return nil, wnfcb.err + } specs := make([]*sqlgraph.CreateSpec, len(wnfcb.builders)) nodes := make([]*WithNilFields, len(wnfcb.builders)) mutators := make([]Mutator, len(wnfcb.builders)) diff --git a/schemast/internal/mutatetest/ent/withnilfields_delete.go b/schemast/internal/mutatetest/ent/withnilfields_delete.go index e7ba76f31..1ee35ed91 100644 --- a/schemast/internal/mutatetest/ent/withnilfields_delete.go +++ b/schemast/internal/mutatetest/ent/withnilfields_delete.go @@ -27,7 +27,7 @@ func (wnfd *WithNilFieldsDelete) Where(ps ...predicate.WithNilFields) *WithNilFi // Exec executes the deletion query and returns how many vertices were deleted. func (wnfd *WithNilFieldsDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, WithNilFieldsMutation](ctx, wnfd.sqlExec, wnfd.mutation, wnfd.hooks) + return withHooks(ctx, wnfd.sqlExec, wnfd.mutation, wnfd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withnilfields_update.go b/schemast/internal/mutatetest/ent/withnilfields_update.go index 3ce0ba69c..3204ac419 100644 --- a/schemast/internal/mutatetest/ent/withnilfields_update.go +++ b/schemast/internal/mutatetest/ent/withnilfields_update.go @@ -34,7 +34,7 @@ func (wnfu *WithNilFieldsUpdate) Mutation() *WithNilFieldsMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (wnfu *WithNilFieldsUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, WithNilFieldsMutation](ctx, wnfu.sqlSave, wnfu.mutation, wnfu.hooks) + return withHooks(ctx, wnfu.sqlSave, wnfu.mutation, wnfu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (wnfuo *WithNilFieldsUpdateOne) Select(field string, fields ...string) *Wit // Save executes the query and returns the updated WithNilFields entity. func (wnfuo *WithNilFieldsUpdateOne) Save(ctx context.Context) (*WithNilFields, error) { - return withHooks[*WithNilFields, WithNilFieldsMutation](ctx, wnfuo.sqlSave, wnfuo.mutation, wnfuo.hooks) + return withHooks(ctx, wnfuo.sqlSave, wnfuo.mutation, wnfuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withoutfields/where.go b/schemast/internal/mutatetest/ent/withoutfields/where.go index d705afaa2..7dea24364 100644 --- a/schemast/internal/mutatetest/ent/withoutfields/where.go +++ b/schemast/internal/mutatetest/ent/withoutfields/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.WithoutFields { // And groups predicates with the AND operator between them. func And(predicates ...predicate.WithoutFields) predicate.WithoutFields { - return predicate.WithoutFields(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithoutFields(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.WithoutFields) predicate.WithoutFields { - return predicate.WithoutFields(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.WithoutFields(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.WithoutFields) predicate.WithoutFields { - return predicate.WithoutFields(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.WithoutFields(sql.NotPredicates(p)) } diff --git a/schemast/internal/mutatetest/ent/withoutfields_create.go b/schemast/internal/mutatetest/ent/withoutfields_create.go index 6ee3d238d..81b511447 100644 --- a/schemast/internal/mutatetest/ent/withoutfields_create.go +++ b/schemast/internal/mutatetest/ent/withoutfields_create.go @@ -25,7 +25,7 @@ func (wfc *WithoutFieldsCreate) Mutation() *WithoutFieldsMutation { // Save creates the WithoutFields in the database. func (wfc *WithoutFieldsCreate) Save(ctx context.Context) (*WithoutFields, error) { - return withHooks[*WithoutFields, WithoutFieldsMutation](ctx, wfc.sqlSave, wfc.mutation, wfc.hooks) + return withHooks(ctx, wfc.sqlSave, wfc.mutation, wfc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (wfc *WithoutFieldsCreate) createSpec() (*WithoutFields, *sqlgraph.CreateSp // WithoutFieldsCreateBulk is the builder for creating many WithoutFields entities in bulk. type WithoutFieldsCreateBulk struct { config + err error builders []*WithoutFieldsCreate } // Save creates the WithoutFields entities in the database. func (wfcb *WithoutFieldsCreateBulk) Save(ctx context.Context) ([]*WithoutFields, error) { + if wfcb.err != nil { + return nil, wfcb.err + } specs := make([]*sqlgraph.CreateSpec, len(wfcb.builders)) nodes := make([]*WithoutFields, len(wfcb.builders)) mutators := make([]Mutator, len(wfcb.builders)) diff --git a/schemast/internal/mutatetest/ent/withoutfields_delete.go b/schemast/internal/mutatetest/ent/withoutfields_delete.go index 6181147fe..56ca69227 100644 --- a/schemast/internal/mutatetest/ent/withoutfields_delete.go +++ b/schemast/internal/mutatetest/ent/withoutfields_delete.go @@ -27,7 +27,7 @@ func (wfd *WithoutFieldsDelete) Where(ps ...predicate.WithoutFields) *WithoutFie // Exec executes the deletion query and returns how many vertices were deleted. func (wfd *WithoutFieldsDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, WithoutFieldsMutation](ctx, wfd.sqlExec, wfd.mutation, wfd.hooks) + return withHooks(ctx, wfd.sqlExec, wfd.mutation, wfd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/mutatetest/ent/withoutfields_update.go b/schemast/internal/mutatetest/ent/withoutfields_update.go index 8cca7037d..abd62ad1f 100644 --- a/schemast/internal/mutatetest/ent/withoutfields_update.go +++ b/schemast/internal/mutatetest/ent/withoutfields_update.go @@ -34,7 +34,7 @@ func (wfu *WithoutFieldsUpdate) Mutation() *WithoutFieldsMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (wfu *WithoutFieldsUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, WithoutFieldsMutation](ctx, wfu.sqlSave, wfu.mutation, wfu.hooks) + return withHooks(ctx, wfu.sqlSave, wfu.mutation, wfu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (wfuo *WithoutFieldsUpdateOne) Select(field string, fields ...string) *With // Save executes the query and returns the updated WithoutFields entity. func (wfuo *WithoutFieldsUpdateOne) Save(ctx context.Context) (*WithoutFields, error) { - return withHooks[*WithoutFields, WithoutFieldsMutation](ctx, wfuo.sqlSave, wfuo.mutation, wfuo.hooks) + return withHooks(ctx, wfuo.sqlSave, wfuo.mutation, wfuo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/schemast/internal/printtest/ent/client.go b/schemast/internal/printtest/ent/client.go index 91a257e04..b42f5ec2d 100644 --- a/schemast/internal/printtest/ent/client.go +++ b/schemast/internal/printtest/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "entgo.io/contrib/schemast/internal/printtest/ent/migrate" "entgo.io/ent" @@ -108,11 +109,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -230,6 +234,21 @@ func (c *MessageClient) CreateBulk(builders ...*MessageCreate) *MessageCreateBul return &MessageCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MessageClient) MapCreateBulk(slice any, setFunc func(*MessageCreate, int)) *MessageCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MessageCreateBulk{err: fmt.Errorf("calling to MessageClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MessageCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MessageCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Message. func (c *MessageClient) Update() *MessageUpdate { mutation := newMessageMutation(c.config, OpUpdate) @@ -348,6 +367,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/schemast/internal/printtest/ent/message/where.go b/schemast/internal/printtest/ent/message/where.go index 1df35a4f8..419de8d38 100644 --- a/schemast/internal/printtest/ent/message/where.go +++ b/schemast/internal/printtest/ent/message/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.Message { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Message) predicate.Message { - return predicate.Message(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Message(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Message) predicate.Message { - return predicate.Message(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Message(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Message) predicate.Message { - return predicate.Message(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Message(sql.NotPredicates(p)) } diff --git a/schemast/internal/printtest/ent/message_create.go b/schemast/internal/printtest/ent/message_create.go index 9ed313770..45a916a88 100644 --- a/schemast/internal/printtest/ent/message_create.go +++ b/schemast/internal/printtest/ent/message_create.go @@ -25,7 +25,7 @@ func (mc *MessageCreate) Mutation() *MessageMutation { // Save creates the Message in the database. func (mc *MessageCreate) Save(ctx context.Context) (*Message, error) { - return withHooks[*Message, MessageMutation](ctx, mc.sqlSave, mc.mutation, mc.hooks) + return withHooks(ctx, mc.sqlSave, mc.mutation, mc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (mc *MessageCreate) createSpec() (*Message, *sqlgraph.CreateSpec) { // MessageCreateBulk is the builder for creating many Message entities in bulk. type MessageCreateBulk struct { config + err error builders []*MessageCreate } // Save creates the Message entities in the database. func (mcb *MessageCreateBulk) Save(ctx context.Context) ([]*Message, error) { + if mcb.err != nil { + return nil, mcb.err + } specs := make([]*sqlgraph.CreateSpec, len(mcb.builders)) nodes := make([]*Message, len(mcb.builders)) mutators := make([]Mutator, len(mcb.builders)) diff --git a/schemast/internal/printtest/ent/message_delete.go b/schemast/internal/printtest/ent/message_delete.go index 2d2eb7488..761fd13ae 100644 --- a/schemast/internal/printtest/ent/message_delete.go +++ b/schemast/internal/printtest/ent/message_delete.go @@ -27,7 +27,7 @@ func (md *MessageDelete) Where(ps ...predicate.Message) *MessageDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (md *MessageDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, MessageMutation](ctx, md.sqlExec, md.mutation, md.hooks) + return withHooks(ctx, md.sqlExec, md.mutation, md.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/printtest/ent/message_update.go b/schemast/internal/printtest/ent/message_update.go index 4e2a8e17b..247d29cd7 100644 --- a/schemast/internal/printtest/ent/message_update.go +++ b/schemast/internal/printtest/ent/message_update.go @@ -34,7 +34,7 @@ func (mu *MessageUpdate) Mutation() *MessageMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (mu *MessageUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, MessageMutation](ctx, mu.sqlSave, mu.mutation, mu.hooks) + return withHooks(ctx, mu.sqlSave, mu.mutation, mu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (muo *MessageUpdateOne) Select(field string, fields ...string) *MessageUpda // Save executes the query and returns the updated Message entity. func (muo *MessageUpdateOne) Save(ctx context.Context) (*Message, error) { - return withHooks[*Message, MessageMutation](ctx, muo.sqlSave, muo.mutation, muo.hooks) + return withHooks(ctx, muo.sqlSave, muo.mutation, muo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/schemast/internal/printtest/ent/runtime/runtime.go b/schemast/internal/printtest/ent/runtime/runtime.go index d6a86d96c..888ac3080 100644 --- a/schemast/internal/printtest/ent/runtime/runtime.go +++ b/schemast/internal/printtest/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in entgo.io/contrib/schemast/internal/printtest/ent/runtime.go const ( - Version = "v0.12.2" // Version of ent codegen. - Sum = "h1:Ndl/JvCX76xCtUDlrUfMnOKBRodAtxE5yfGYxjbOxmM=" // Sum of ent codegen. + Version = "v0.12.5-0.20231110085726-c2ff3ff3bca9" // Version of ent codegen. + Sum = "h1:xj+sGA76NTV89qO0RqbEfUy5/358HYQogf4nXwnSQwE=" // Sum of ent codegen. ) diff --git a/schemast/internal/printtest/ent/user/where.go b/schemast/internal/printtest/ent/user/where.go index 73daa1eb7..257c27fea 100644 --- a/schemast/internal/printtest/ent/user/where.go +++ b/schemast/internal/printtest/ent/user/where.go @@ -54,32 +54,15 @@ func IDLTE(id int) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/schemast/internal/printtest/ent/user_create.go b/schemast/internal/printtest/ent/user_create.go index 97ca80dbd..d98d00a02 100644 --- a/schemast/internal/printtest/ent/user_create.go +++ b/schemast/internal/printtest/ent/user_create.go @@ -25,7 +25,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -84,11 +84,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) diff --git a/schemast/internal/printtest/ent/user_delete.go b/schemast/internal/printtest/ent/user_delete.go index 9a8e643ec..b032799f7 100644 --- a/schemast/internal/printtest/ent/user_delete.go +++ b/schemast/internal/printtest/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/schemast/internal/printtest/ent/user_update.go b/schemast/internal/printtest/ent/user_update.go index fa591754f..d9b3e2b3b 100644 --- a/schemast/internal/printtest/ent/user_update.go +++ b/schemast/internal/printtest/ent/user_update.go @@ -34,7 +34,7 @@ func (uu *UserUpdate) Mutation() *UserMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs.