Repository navigation
refactor(hooks+composites): unify Delete signature, inline Select/Omit builders, add composite PK name support, wrap constraints as typed structs with EQ(), and add AppendData helper - #75
Merged
Conversation
1- Define CompositePK as a *CompositePK struct, that has Fields as []string, and Name as a string 2- Update resolveModelAttributes() in resolver, case id, calls the already existing resolveFieldNameListWithName() with @@id, assign m.CompositePK = &CompositePK{} 3- Remove resolveFieldNameList() as @@id uses resolveFieldNameListWithName() that supports parsing name 4- Adapt callsites in convertToAtlasSchema, in buildPrimaryKey() to use CompositePK.Fields, and to apply nil checks 5- Update template usage to use CompositePK.Fields, and CompositePK.Name, achieving 1 logical column
…east one unique predicate and variadic predicates, unique or non-unique 1- Change Delete() to accept where as UniquePredicate[M], and additional ...PredicateOf[M] 2- Build allWhere inside executeDelete() to pass it down as a slice of predicates, as unique predicates are fundamentally predicates, they enforce uniqueness at the top level function, then pass down to the run func to execute SQL 3- Update runDelete() to loop over where, to validate each predicate, as it is a slice now 4- Update some callsites using old signature to match the new one, update any use of CompositePK the was inquiring for fields to use CompositePK.Fields 5- Add additional field on DeleteBuilder, change execFunc signature to accept the where and additional
1- Remove separate FindUniqueSelectBuilder, FindUniqueOmitBuilder,FindFirstSelectBuilder, FindFirstOmitBuilder, FindManySelectBuilder, and FindManyOmitBuilder, Select() and Omit() now mutate the main builder and return self, matching the existing pattern used by DeleteBuilder and UpdateBuilder
…easy appending for records to create
- Update {Model}DeleteArgs to take a []PredicateOf[M] instead of a unique predicate to match Prisma's style of at least one required unique and a variadic of additional (same as findUnique)
- Update integration tests to properly use hooks and compound PKs as they take.EQ() instead of {Name}Unique(), makes it consistent with the scalar fields, as they result in a logical column
- Refactor integration/main.go into modular functions to toggle on and off in main (it's just a playgroud)
…s with EQ() method
1- Replace standalone {Name}Unique() free functions with {name} struct embedding CompositeUniqueConstraint and exposing EQ() method
2- Default composite PK names use underscore separation (Field1_Field2)
3- Keep Column as the composite name and Value as map[string]any for hooks
4- Use IsLogical: true with AND operator for natural validation recursion
…r compound PKs, and updating top level delete operation - Add composite_test, covers EQ() predicate introspection (Column/Value types), composite PK find/delete/update, composite OnConflict (Ignore, UpdateNewValues), and all hook interaction patterns (inspect, replace, append, mixed composite+simple predicates)
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.
feat(schema): Add support for composite PK names
1- Define CompositePK as a *CompositePK struct, that has Fields as []string, and Name as a string
2- Update resolveModelAttributes() in resolver, case id, calls the already existing resolveFieldNameListWithName() with @@id, assign m.CompositePK = &CompositePK{}
3- Remove resolveFieldNameList() as @@id uses resolveFieldNameListWithName() that supports parsing name
4- Adapt callsites in convertToAtlasSchema, in buildPrimaryKey() to use CompositePK.Fields, and to apply nil checks
5- Update template usage to use CompositePK.Fields, and CompositePK.Name, achieving 1 logical column
refactor(delete hooks): Change Delete function signature to take at least one unique predicate and variadic predicates, unique or non-unique
1- Change Delete() to accept where as UniquePredicate[M], and additional ...PredicateOf[M]
2- Build allWhere inside executeDelete() to pass it down as a slice of predicates, as unique predicates are fundamentally predicates, they enforce uniqueness at the top level function, then pass down to the run func to execute SQL
3- Update runDelete() to loop over where, to validate each predicate, as it is a slice now
4- Update some callsites using old signature to match the new one, update any use of CompositePK the was inquiring for fields to use CompositePK.Fields
5- Add additional field on DeleteBuilder, change execFunc signature to accept the where and additional
refactor(builders): inline Select/Omit into query builders
1- Remove separate FindUniqueSelectBuilder, FindUniqueOmitBuilder,FindFirstSelectBuilder, FindFirstOmitBuilder, FindManySelectBuilder, and FindManyOmitBuilder, Select() and Omit() now mutate the main builder and return self, matching the existing pattern used by DeleteBuilder and UpdateBuilder
feat(create hooks): Add AppendData() on CreateMany/AndReturnArgs for easy appending for records to create
Update {Model}DeleteArgs to take a []PredicateOf[M] instead of a unique predicate to match Prisma's style of at least one required unique and a variadic of additional (same as findUnique)
Update integration tests to properly use hooks and compound PKs as they take.EQ() instead of {Name}Unique(), makes it consistent with the scalar fields, as they result in a logical column
Refactor integration/main.go into modular functions to toggle on and off in main (it's just a playgroud)
refactor(model_predicate): wrap composite constraints in typed structs with EQ() method
1- Replace standalone {Name}Unique() free functions with {name} struct embedding CompositeUniqueConstraint and exposing EQ() method
2- Default composite PK names use underscore separation (Field1_Field2)
3- Keep Column as the composite name and Value as map[string]any for hooks
4- Use IsLogical: true with AND operator for natural validation recursion
updated generated client after refactoring hooks, add name support for compound PKs, and updating top level delete operation