Feat: Implement createMany and CreateManyAndReturn - #15
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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