Skip to content

Feat: Implement createMany and CreateManyAndReturn - #15

Merged
VoidClancy merged 2 commits into
masterfrom
codegen
Jul 5, 2026
Merged

Feat: Implement createMany and CreateManyAndReturn#15
VoidClancy merged 2 commits into
masterfrom
codegen

Conversation

@VoidClancy

Copy link
Copy Markdown
Owner

1- define hasAnyLog() for easy imports in the main client of the log package in case any log levels were configured, to avoid verbose if condition

2- define CreateManyBuilder, CreateManyAndReturnBuilder, and their associated select and omit builders,generics in the same modular style of CreateBuilder

3- define a SupportsBulkInsert() on the client dialect, to insert in bulk if the DB supports, or to fall back to a loop in a transaction if it doesn't (Sqlite), implement the function for both PG and Sqlite

4- Refactor the duplicates between create, createMany, and createManyAndReturn:
a- Consolidated all per-field insert branching logic (cuid/uuid generation, defaults, optional fields, array handling) exclusively into the generated {{Model}}InputToMap method

b- Introduced a package-level runtime helper mapToColsVals in relations_runtime.gotpl to map a model input map to structured columns and values based on a generated stable column order slice ({{Model}}ColOrder)

c- Replaced duplicate inline column mapping inside execute{{Model}}Create with calls to {{Model}}InputToMap and mapToColsVals

d- Extracted duplicate bulk SQL generation logic (column union computation, value flattening, query param binding, and dialect-specific RETURNING clauses) into a shared runtime helper buildBulkInsertSQL

e- Updated execute{{Model}}CreateMany and execute{{Model}}CreateManyAndReturn to delegate SQL construction to buildBulkInsertSQL

f- Consolidated relation check template OR-chains into a single generated hasAnyRelation() helper method on *{{Model}}Select to check relation selections cleanly

5- test createMany, and the returning count, and test createManyAndReturn that it supports select too

1- define hasAnyLog() for easy imports in the main client of the log package in case any log levels were configured, to avoid verbose if condition

2- define CreateManyBuilder, CreateManyAndReturnBuilder, and their associated select and omit builders,generics in the same modular style of CreateBuilder

3- define a SupportsBulkInsert() on the client dialect, to insert in bulk if the DB supports, or to fall back to a loop in a transaction if it doesn't (Sqlite), implement the function for both PG and Sqlite

4- Refactor the duplicates between create, createMany, and createManyAndReturn:
   a- Consolidated all per-field insert branching logic (cuid/uuid generation, defaults, optional fields, array handling) exclusively into the generated {{Model}}InputToMap method
   b- Introduced a package-level runtime helper mapToColsVals in relations_runtime.gotpl to map a model input map to structured columns and values based on a generated stable column order slice ({{Model}}ColOrder)
   c- Replaced duplicate inline column mapping inside execute{{Model}}Create with calls to {{Model}}InputToMap and mapToColsVals
   d- Extracted duplicate bulk SQL generation logic (column union computation, value flattening, query param binding, and dialect-specific RETURNING clauses) into a shared runtime helper buildBulkInsertSQL
   e- Updated execute{{Model}}CreateMany and execute{{Model}}CreateManyAndReturn to delegate SQL construction to buildBulkInsertSQL
   f- Consolidated relation check template OR-chains into a single generated hasAnyRelation() helper method on *{{Model}}Select to check relation selections cleanly

5- test createMany, and the returning count, and test createManyAndReturn that it supports select too
@VoidClancy VoidClancy self-assigned this Jul 5, 2026
@VoidClancy
VoidClancy merged commit d749b7a into master Jul 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant