Commit 0797d7a
authored
feat(repository): add composite primary key support (#640)
Adds support for composite (multi-column) primary keys in the repository layer.
Changes:
- Add PrimaryKeyType type alias supporting scalar, tuple, and dict formats
- Add helper methods for composite key handling:
- _is_composite_pk(): Check if model has composite PK
- _build_pk_filter(): Build WHERE clause for PK lookup
- _extract_pk_value(): Extract PK value(s) from instance
- _pk_values_present(): Check if all PK values are set
- _normalize_pk_values_to_tuples(): Convert PK values to tuples for bulk ops
- Update get() to support composite keys (tuple or dict input)
- Update delete() to support composite keys
- Update delete_many() to use tuple_().in_() for efficient bulk operations
- Cache PK columns in __init__ for performance
The implementation follows SQLAlchemy's native patterns and maintains
full backward compatibility for single-column primary keys.
Closes #1891 parent 4001b0f commit 0797d7a
19 files changed
Lines changed: 3098 additions & 1037 deletions
File tree
- advanced_alchemy
- repository
- memory
- service
- docs/usage
- tests
- integration
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
0 commit comments