Skip to content

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
VoidClancy merged 6 commits into
masterfrom
hooks
Jul 29, 2026

Conversation

@VoidClancy

Copy link
Copy Markdown
Owner

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

  • 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)

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)
@VoidClancy VoidClancy self-assigned this Jul 29, 2026
@VoidClancy
VoidClancy merged commit 13dffc1 into master Jul 29, 2026
11 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