From 255ad20088da77eb55cf03a9cc45b9b67575d493 Mon Sep 17 00:00:00 2001 From: Clancy Date: Thu, 9 Jul 2026 21:48:46 +0300 Subject: [PATCH] Feat: implement a separate afterCreateMany hook 1- implement afterCreateMany giving access to a slice of userCreate struct, which are the arguments used in this createMany as it returns only a count, along with the count of records created 2- apply the hook if present in the excute{model}createMany 3- add test cases for the afterCreateMany hook --- generator/templates/client.gotpl | 1 + generator/templates/model_create.gotpl | 13 ++++- generator/templates/model_structs.gotpl | 11 +++- integration/create_many_test.go | 75 +++++++++++++++++++++++++ integration/main.go | 27 +++++---- integration/makefile | 4 +- integration/valk/category.go | 24 ++++++-- integration/valk/categoryToPost.go | 24 ++++++-- integration/valk/client.go | 6 ++ integration/valk/comment.go | 24 ++++++-- integration/valk/post.go | 24 ++++++-- integration/valk/profile.go | 24 ++++++-- integration/valk/user.go | 24 ++++++-- 13 files changed, 241 insertions(+), 40 deletions(-) diff --git a/generator/templates/client.gotpl b/generator/templates/client.gotpl index 1df8137..b3deb00 100644 --- a/generator/templates/client.gotpl +++ b/generator/templates/client.gotpl @@ -93,6 +93,7 @@ func (q *Queries) copyHooksFrom(other *Queries) { {{- range $model := .Schema.Models }} q.{{ $model.Name }}.beforeCreate = other.{{ $model.Name }}.beforeCreate q.{{ $model.Name }}.afterCreate = other.{{ $model.Name }}.afterCreate + q.{{ $model.Name }}.afterCreateMany = other.{{ $model.Name }}.afterCreateMany {{- end }} } diff --git a/generator/templates/model_create.gotpl b/generator/templates/model_create.gotpl index 9ccd885..2f940b2 100644 --- a/generator/templates/model_create.gotpl +++ b/generator/templates/model_create.gotpl @@ -342,6 +342,7 @@ func (d *{{ .Model.Name }}Delegate) CreateManyAndReturn(records ...RecordInput) func (q *Queries) execute{{ .Model.Name }}CreateMany(ctx context.Context, records []RecordInput) (int64, error) { rowMaps := make([]map[string]any, len(records)) + inputs := make([]{{ .Model.Name }}Create, len(records)) for i, rec := range records { if err := validate{{ .Model.Name }}Create(rec.Assignments); err != nil { return 0, fmt.Errorf("validation failed at index %d: %w", i, err) @@ -353,8 +354,18 @@ func (q *Queries) execute{{ .Model.Name }}CreateMany(ctx context.Context, record } } rowMaps[i] = input.ToRowMap() + inputs[i] = input } - return executeCreateMany(ctx, q, rowMaps, "{{ .Model.EffectiveTableName }}", {{ .Model.Name }}ColOrder) + count, err := executeCreateMany(ctx, q, rowMaps, "{{ .Model.EffectiveTableName }}", {{ .Model.Name }}ColOrder) + if err != nil { + return 0, err + } + if q.{{ .Model.Name }}.afterCreateMany != nil { + if err := q.{{ .Model.Name }}.afterCreateMany(ctx, inputs, count); err != nil { + return 0, err + } + } + return count, nil } func (q *Queries) execute{{ .Model.Name }}CreateManyAndReturn(ctx context.Context, records []RecordInput, selects *{{ .Model.Name }}Select, omits *{{ .Model.Name }}Omit) ([]*{{ .Model.Name }}, error) { diff --git a/generator/templates/model_structs.gotpl b/generator/templates/model_structs.gotpl index c1eac27..d9a573a 100644 --- a/generator/templates/model_structs.gotpl +++ b/generator/templates/model_structs.gotpl @@ -36,9 +36,10 @@ type {{ .Model.Name }}Omit struct { } type {{ .Model.Name }}Delegate struct { - client *Queries - beforeCreate func(context.Context, *{{ .Model.Name }}Create) error - afterCreate func(context.Context, *{{ .Model.Name }}) error + client *Queries + beforeCreate func(context.Context, *{{ .Model.Name }}Create) error + afterCreate func(context.Context, *{{ .Model.Name }}) error + afterCreateMany func(context.Context, []{{ .Model.Name }}Create, int64) error } func (d *{{ .Model.Name }}Delegate) BeforeCreate(hook func(context.Context, *{{ .Model.Name }}Create) error) { @@ -49,6 +50,10 @@ func (d *{{ .Model.Name }}Delegate) AfterCreate(hook func(context.Context, *{{ . d.afterCreate = hook } +func (d *{{ .Model.Name }}Delegate) AfterCreateMany(hook func(context.Context, []{{ .Model.Name }}Create, int64) error) { + d.afterCreateMany = hook +} + func (m *{{ .Model.Name }}) ScanFields(cols []string) []any { targets := make([]any, len(cols)) for i, col := range cols { diff --git a/integration/create_many_test.go b/integration/create_many_test.go index 1e8c2d2..8d4d8c4 100644 --- a/integration/create_many_test.go +++ b/integration/create_many_test.go @@ -161,6 +161,81 @@ func TestCreateMany_Hooks(t *testing.T) { t.Fatalf("expected %d rows (insert still committed), got %d", prevCount+1, count) } }) + + t.Run("AfterCreateMany hook receives structs and count", func(t *testing.T) { + client, cleanup := setupTestDB(t) + defer cleanup() + + var gotUsers []valk.UserCreate + var gotCount int64 + client.User.AfterCreateMany(func(ctx context.Context, users []valk.UserCreate, count int64) error { + gotUsers = users + gotCount = count + return nil + }) + + count, err := client.User.CreateMany( + user.Record( + user.Email.Set("bulk1@example.com"), + user.PhoneNum.Set("+700000001"), + ), + user.Record( + user.Email.Set("bulk2@example.com"), + user.PhoneNum.Set("+700000002"), + ), + ).Exec(ctx) + + if err != nil { + t.Fatalf("CreateMany failed: %v", err) + } + if count != 2 { + t.Fatalf("expected count 2, got %d", count) + } + if gotCount != 2 { + t.Fatalf("expected hook count 2, got %d", gotCount) + } + if len(gotUsers) != 2 { + t.Fatalf("expected 2 users in hook, got %d", len(gotUsers)) + } + if gotUsers[0].Email != "bulk1@example.com" { + t.Errorf("expected email 'bulk1@example.com', got %q", gotUsers[0].Email) + } + if gotUsers[1].Email != "bulk2@example.com" { + t.Errorf("expected email 'bulk2@example.com', got %q", gotUsers[1].Email) + } + }) + + t.Run("AfterCreateMany hook error does not rollback inserts", func(t *testing.T) { + client, cleanup := setupTestDB(t) + defer cleanup() + + client.User.AfterCreateMany(func(ctx context.Context, users []valk.UserCreate, count int64) error { + return fmt.Errorf("after create many rejected") + }) + + _, err := client.User.CreateMany( + user.Record( + user.Email.Set("ghost@example.com"), + user.PhoneNum.Set("+800000000"), + ), + ).Exec(ctx) + + if err == nil { + t.Fatal("expected error from AfterCreateMany rejection, got nil") + } + if !strings.Contains(err.Error(), "after create many rejected") { + t.Errorf("expected 'after create many rejected' in error, got %v", err) + } + + var count int + client.Raw().QueryRowContext(ctx, query( + `SELECT count(*) FROM "User" WHERE email = 'ghost@example.com'`, + `SELECT count(*) FROM "User" WHERE email = 'ghost@example.com'`, + )).Scan(&count) + if count != 1 { + t.Fatalf("expected row to still exist (insert committed before hook), got %d", count) + } + }) } func TestCreateMany(t *testing.T) { diff --git a/integration/main.go b/integration/main.go index 5f49f72..3d2218b 100644 --- a/integration/main.go +++ b/integration/main.go @@ -26,16 +26,23 @@ type SeedData struct { } func seed(db *valk.DB, ctx context.Context) *SeedData { - db.User.BeforeCreate(func(ctx context.Context, user *valk.UserCreate) error { + db.User.BeforeCreate(func(ctx context.Context, user *valk.UserCreate) error { user.Role = new(valk.UserRole.Admin) + return nil + }) + db.User.AfterCreateMany(func(ctx context.Context, users []valk.UserCreate, count int64) error { + var emails []string + for _, u := range users { + emails = append(emails, u.Email) + } + fmt.Printf("AfterCreateMany: %d users created (emails: %v)\n", count, emails) return nil }) db.User.AfterCreate(func(ctx context.Context, user *valk.User) error { - fmt.Println("CREATED USER WITH ID: ", user.Id) - fmt.Println("USER ROLE: ", user.Role) + fmt.Printf("AfterCreate: user %s (role=%s)\n", user.Email, user.Role) return nil }) @@ -53,22 +60,22 @@ func seed(db *valk.DB, ctx context.Context) *SeedData { if err != nil { log.Fatalf("failed to create users: %v", err) } + fmt.Printf("CreateManyAndReturn: %d users returned with auto-generated IDs\n", len(users)) - for _, u := range users { - - fmt.Println("USER ROLE: ", u.Role) - } - - _, err = db.User.CreateMany( + if _, err := db.User.CreateMany( user.Record( user.Email.Set("test"), + user.PhoneNum.Set("555-test"), user.Password.Set("passwd"), ), user.Record( user.Email.Set("again"), + user.PhoneNum.Set("555-again"), user.Password.Set("123456"), ), - ).Exec(ctx) + ).Exec(ctx); err != nil { + log.Fatalf("failed to CreateMany: %v", err) + } referrer, err := db.User.Create( user.Email.Set("referrer@example.com"), user.PhoneNum.Set("555-0001"), diff --git a/integration/makefile b/integration/makefile index a6d5832..1cd5811 100644 --- a/integration/makefile +++ b/integration/makefile @@ -1,10 +1,10 @@ .PHONY: build run test build: - go build -o bin/sandbox + go build -o bin/integ run: - go build -o bin/sandbox && ./bin/sandbox + go run main.go test: go test -v ./... \ No newline at end of file diff --git a/integration/valk/category.go b/integration/valk/category.go index b53993e..9304d6f 100644 --- a/integration/valk/category.go +++ b/integration/valk/category.go @@ -36,9 +36,10 @@ type CategoryOmit struct { } type CategoryDelegate struct { - client *Queries - beforeCreate func(context.Context, *CategoryCreate) error - afterCreate func(context.Context, *Category) error + client *Queries + beforeCreate func(context.Context, *CategoryCreate) error + afterCreate func(context.Context, *Category) error + afterCreateMany func(context.Context, []CategoryCreate, int64) error } func (d *CategoryDelegate) BeforeCreate(hook func(context.Context, *CategoryCreate) error) { @@ -49,6 +50,10 @@ func (d *CategoryDelegate) AfterCreate(hook func(context.Context, *Category) err d.afterCreate = hook } +func (d *CategoryDelegate) AfterCreateMany(hook func(context.Context, []CategoryCreate, int64) error) { + d.afterCreateMany = hook +} + func (m *Category) ScanFields(cols []string) []any { targets := make([]any, len(cols)) for i, col := range cols { @@ -245,6 +250,7 @@ func (d *CategoryDelegate) CreateManyAndReturn(records ...RecordInput) *CreateMa func (q *Queries) executeCategoryCreateMany(ctx context.Context, records []RecordInput) (int64, error) { rowMaps := make([]map[string]any, len(records)) + inputs := make([]CategoryCreate, len(records)) for i, rec := range records { if err := validateCategoryCreate(rec.Assignments); err != nil { return 0, fmt.Errorf("validation failed at index %d: %w", i, err) @@ -256,8 +262,18 @@ func (q *Queries) executeCategoryCreateMany(ctx context.Context, records []Recor } } rowMaps[i] = input.ToRowMap() + inputs[i] = input + } + count, err := executeCreateMany(ctx, q, rowMaps, "Category", CategoryColOrder) + if err != nil { + return 0, err + } + if q.Category.afterCreateMany != nil { + if err := q.Category.afterCreateMany(ctx, inputs, count); err != nil { + return 0, err + } } - return executeCreateMany(ctx, q, rowMaps, "Category", CategoryColOrder) + return count, nil } func (q *Queries) executeCategoryCreateManyAndReturn(ctx context.Context, records []RecordInput, selects *CategorySelect, omits *CategoryOmit) ([]*Category, error) { diff --git a/integration/valk/categoryToPost.go b/integration/valk/categoryToPost.go index 6261c7e..a9fed6d 100644 --- a/integration/valk/categoryToPost.go +++ b/integration/valk/categoryToPost.go @@ -39,9 +39,10 @@ type CategoryToPostOmit struct { } type CategoryToPostDelegate struct { - client *Queries - beforeCreate func(context.Context, *CategoryToPostCreate) error - afterCreate func(context.Context, *CategoryToPost) error + client *Queries + beforeCreate func(context.Context, *CategoryToPostCreate) error + afterCreate func(context.Context, *CategoryToPost) error + afterCreateMany func(context.Context, []CategoryToPostCreate, int64) error } func (d *CategoryToPostDelegate) BeforeCreate(hook func(context.Context, *CategoryToPostCreate) error) { @@ -52,6 +53,10 @@ func (d *CategoryToPostDelegate) AfterCreate(hook func(context.Context, *Categor d.afterCreate = hook } +func (d *CategoryToPostDelegate) AfterCreateMany(hook func(context.Context, []CategoryToPostCreate, int64) error) { + d.afterCreateMany = hook +} + func (m *CategoryToPost) ScanFields(cols []string) []any { targets := make([]any, len(cols)) for i, col := range cols { @@ -244,6 +249,7 @@ func (d *CategoryToPostDelegate) CreateManyAndReturn(records ...RecordInput) *Cr func (q *Queries) executeCategoryToPostCreateMany(ctx context.Context, records []RecordInput) (int64, error) { rowMaps := make([]map[string]any, len(records)) + inputs := make([]CategoryToPostCreate, len(records)) for i, rec := range records { if err := validateCategoryToPostCreate(rec.Assignments); err != nil { return 0, fmt.Errorf("validation failed at index %d: %w", i, err) @@ -255,8 +261,18 @@ func (q *Queries) executeCategoryToPostCreateMany(ctx context.Context, records [ } } rowMaps[i] = input.ToRowMap() + inputs[i] = input + } + count, err := executeCreateMany(ctx, q, rowMaps, "CategoryToPost", CategoryToPostColOrder) + if err != nil { + return 0, err + } + if q.CategoryToPost.afterCreateMany != nil { + if err := q.CategoryToPost.afterCreateMany(ctx, inputs, count); err != nil { + return 0, err + } } - return executeCreateMany(ctx, q, rowMaps, "CategoryToPost", CategoryToPostColOrder) + return count, nil } func (q *Queries) executeCategoryToPostCreateManyAndReturn(ctx context.Context, records []RecordInput, selects *CategoryToPostSelect, omits *CategoryToPostOmit) ([]*CategoryToPost, error) { diff --git a/integration/valk/client.go b/integration/valk/client.go index 02e302a..8816190 100644 --- a/integration/valk/client.go +++ b/integration/valk/client.go @@ -240,16 +240,22 @@ func (q *Queries) initDelegates() { func (q *Queries) copyHooksFrom(other *Queries) { q.User.beforeCreate = other.User.beforeCreate q.User.afterCreate = other.User.afterCreate + q.User.afterCreateMany = other.User.afterCreateMany q.Profile.beforeCreate = other.Profile.beforeCreate q.Profile.afterCreate = other.Profile.afterCreate + q.Profile.afterCreateMany = other.Profile.afterCreateMany q.Post.beforeCreate = other.Post.beforeCreate q.Post.afterCreate = other.Post.afterCreate + q.Post.afterCreateMany = other.Post.afterCreateMany q.Comment.beforeCreate = other.Comment.beforeCreate q.Comment.afterCreate = other.Comment.afterCreate + q.Comment.afterCreateMany = other.Comment.afterCreateMany q.Category.beforeCreate = other.Category.beforeCreate q.Category.afterCreate = other.Category.afterCreate + q.Category.afterCreateMany = other.Category.afterCreateMany q.CategoryToPost.beforeCreate = other.CategoryToPost.beforeCreate q.CategoryToPost.afterCreate = other.CategoryToPost.afterCreate + q.CategoryToPost.afterCreateMany = other.CategoryToPost.afterCreateMany } // Close closes the database connection. diff --git a/integration/valk/comment.go b/integration/valk/comment.go index ec2497f..bdebd76 100644 --- a/integration/valk/comment.go +++ b/integration/valk/comment.go @@ -64,9 +64,10 @@ type CommentOmit struct { } type CommentDelegate struct { - client *Queries - beforeCreate func(context.Context, *CommentCreate) error - afterCreate func(context.Context, *Comment) error + client *Queries + beforeCreate func(context.Context, *CommentCreate) error + afterCreate func(context.Context, *Comment) error + afterCreateMany func(context.Context, []CommentCreate, int64) error } func (d *CommentDelegate) BeforeCreate(hook func(context.Context, *CommentCreate) error) { @@ -77,6 +78,10 @@ func (d *CommentDelegate) AfterCreate(hook func(context.Context, *Comment) error d.afterCreate = hook } +func (d *CommentDelegate) AfterCreateMany(hook func(context.Context, []CommentCreate, int64) error) { + d.afterCreateMany = hook +} + func (m *Comment) ScanFields(cols []string) []any { targets := make([]any, len(cols)) for i, col := range cols { @@ -410,6 +415,7 @@ func (d *CommentDelegate) CreateManyAndReturn(records ...RecordInput) *CreateMan func (q *Queries) executeCommentCreateMany(ctx context.Context, records []RecordInput) (int64, error) { rowMaps := make([]map[string]any, len(records)) + inputs := make([]CommentCreate, len(records)) for i, rec := range records { if err := validateCommentCreate(rec.Assignments); err != nil { return 0, fmt.Errorf("validation failed at index %d: %w", i, err) @@ -421,8 +427,18 @@ func (q *Queries) executeCommentCreateMany(ctx context.Context, records []Record } } rowMaps[i] = input.ToRowMap() + inputs[i] = input + } + count, err := executeCreateMany(ctx, q, rowMaps, "Comment", CommentColOrder) + if err != nil { + return 0, err + } + if q.Comment.afterCreateMany != nil { + if err := q.Comment.afterCreateMany(ctx, inputs, count); err != nil { + return 0, err + } } - return executeCreateMany(ctx, q, rowMaps, "Comment", CommentColOrder) + return count, nil } func (q *Queries) executeCommentCreateManyAndReturn(ctx context.Context, records []RecordInput, selects *CommentSelect, omits *CommentOmit) ([]*Comment, error) { diff --git a/integration/valk/post.go b/integration/valk/post.go index bd56914..d8f70d3 100644 --- a/integration/valk/post.go +++ b/integration/valk/post.go @@ -54,9 +54,10 @@ type PostOmit struct { } type PostDelegate struct { - client *Queries - beforeCreate func(context.Context, *PostCreate) error - afterCreate func(context.Context, *Post) error + client *Queries + beforeCreate func(context.Context, *PostCreate) error + afterCreate func(context.Context, *Post) error + afterCreateMany func(context.Context, []PostCreate, int64) error } func (d *PostDelegate) BeforeCreate(hook func(context.Context, *PostCreate) error) { @@ -67,6 +68,10 @@ func (d *PostDelegate) AfterCreate(hook func(context.Context, *Post) error) { d.afterCreate = hook } +func (d *PostDelegate) AfterCreateMany(hook func(context.Context, []PostCreate, int64) error) { + d.afterCreateMany = hook +} + func (m *Post) ScanFields(cols []string) []any { targets := make([]any, len(cols)) for i, col := range cols { @@ -337,6 +342,7 @@ func (d *PostDelegate) CreateManyAndReturn(records ...RecordInput) *CreateManyAn func (q *Queries) executePostCreateMany(ctx context.Context, records []RecordInput) (int64, error) { rowMaps := make([]map[string]any, len(records)) + inputs := make([]PostCreate, len(records)) for i, rec := range records { if err := validatePostCreate(rec.Assignments); err != nil { return 0, fmt.Errorf("validation failed at index %d: %w", i, err) @@ -348,8 +354,18 @@ func (q *Queries) executePostCreateMany(ctx context.Context, records []RecordInp } } rowMaps[i] = input.ToRowMap() + inputs[i] = input + } + count, err := executeCreateMany(ctx, q, rowMaps, "Post", PostColOrder) + if err != nil { + return 0, err + } + if q.Post.afterCreateMany != nil { + if err := q.Post.afterCreateMany(ctx, inputs, count); err != nil { + return 0, err + } } - return executeCreateMany(ctx, q, rowMaps, "Post", PostColOrder) + return count, nil } func (q *Queries) executePostCreateManyAndReturn(ctx context.Context, records []RecordInput, selects *PostSelect, omits *PostOmit) ([]*Post, error) { diff --git a/integration/valk/profile.go b/integration/valk/profile.go index 84aa63f..dfad3c8 100644 --- a/integration/valk/profile.go +++ b/integration/valk/profile.go @@ -40,9 +40,10 @@ type ProfileOmit struct { } type ProfileDelegate struct { - client *Queries - beforeCreate func(context.Context, *ProfileCreate) error - afterCreate func(context.Context, *Profile) error + client *Queries + beforeCreate func(context.Context, *ProfileCreate) error + afterCreate func(context.Context, *Profile) error + afterCreateMany func(context.Context, []ProfileCreate, int64) error } func (d *ProfileDelegate) BeforeCreate(hook func(context.Context, *ProfileCreate) error) { @@ -53,6 +54,10 @@ func (d *ProfileDelegate) AfterCreate(hook func(context.Context, *Profile) error d.afterCreate = hook } +func (d *ProfileDelegate) AfterCreateMany(hook func(context.Context, []ProfileCreate, int64) error) { + d.afterCreateMany = hook +} + func (m *Profile) ScanFields(cols []string) []any { targets := make([]any, len(cols)) for i, col := range cols { @@ -279,6 +284,7 @@ func (d *ProfileDelegate) CreateManyAndReturn(records ...RecordInput) *CreateMan func (q *Queries) executeProfileCreateMany(ctx context.Context, records []RecordInput) (int64, error) { rowMaps := make([]map[string]any, len(records)) + inputs := make([]ProfileCreate, len(records)) for i, rec := range records { if err := validateProfileCreate(rec.Assignments); err != nil { return 0, fmt.Errorf("validation failed at index %d: %w", i, err) @@ -290,8 +296,18 @@ func (q *Queries) executeProfileCreateMany(ctx context.Context, records []Record } } rowMaps[i] = input.ToRowMap() + inputs[i] = input + } + count, err := executeCreateMany(ctx, q, rowMaps, "Profile", ProfileColOrder) + if err != nil { + return 0, err + } + if q.Profile.afterCreateMany != nil { + if err := q.Profile.afterCreateMany(ctx, inputs, count); err != nil { + return 0, err + } } - return executeCreateMany(ctx, q, rowMaps, "Profile", ProfileColOrder) + return count, nil } func (q *Queries) executeProfileCreateManyAndReturn(ctx context.Context, records []RecordInput, selects *ProfileSelect, omits *ProfileOmit) ([]*Profile, error) { diff --git a/integration/valk/user.go b/integration/valk/user.go index 49ec04a..5b9cae9 100644 --- a/integration/valk/user.go +++ b/integration/valk/user.go @@ -68,9 +68,10 @@ type UserOmit struct { } type UserDelegate struct { - client *Queries - beforeCreate func(context.Context, *UserCreate) error - afterCreate func(context.Context, *User) error + client *Queries + beforeCreate func(context.Context, *UserCreate) error + afterCreate func(context.Context, *User) error + afterCreateMany func(context.Context, []UserCreate, int64) error } func (d *UserDelegate) BeforeCreate(hook func(context.Context, *UserCreate) error) { @@ -81,6 +82,10 @@ func (d *UserDelegate) AfterCreate(hook func(context.Context, *User) error) { d.afterCreate = hook } +func (d *UserDelegate) AfterCreateMany(hook func(context.Context, []UserCreate, int64) error) { + d.afterCreateMany = hook +} + func (m *User) ScanFields(cols []string) []any { targets := make([]any, len(cols)) for i, col := range cols { @@ -391,6 +396,7 @@ func (d *UserDelegate) CreateManyAndReturn(records ...RecordInput) *CreateManyAn func (q *Queries) executeUserCreateMany(ctx context.Context, records []RecordInput) (int64, error) { rowMaps := make([]map[string]any, len(records)) + inputs := make([]UserCreate, len(records)) for i, rec := range records { if err := validateUserCreate(rec.Assignments); err != nil { return 0, fmt.Errorf("validation failed at index %d: %w", i, err) @@ -402,8 +408,18 @@ func (q *Queries) executeUserCreateMany(ctx context.Context, records []RecordInp } } rowMaps[i] = input.ToRowMap() + inputs[i] = input + } + count, err := executeCreateMany(ctx, q, rowMaps, "User", UserColOrder) + if err != nil { + return 0, err + } + if q.User.afterCreateMany != nil { + if err := q.User.afterCreateMany(ctx, inputs, count); err != nil { + return 0, err + } } - return executeCreateMany(ctx, q, rowMaps, "User", UserColOrder) + return count, nil } func (q *Queries) executeUserCreateManyAndReturn(ctx context.Context, records []RecordInput, selects *UserSelect, omits *UserOmit) ([]*User, error) {