feat: custom primary key generator
New feature! Custom generator for primary key.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
f04e6db) to head (4fce44e). Report is 1 commits behind head on main.
:white_check_mark: All tests successful. No failed tests found.
Additional details and impacted files
@@ Coverage Diff @@
## main #1618 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 56 56
Lines 1823 1824 +1
Branches 422 423 +1
=========================================
+ Hits 1823 1824 +1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Bundle Report
Changes will increase total bundle size by 240 bytes (0.0%) :arrow_up:. This is within the configured threshold :white_check_mark:
Detailed changes
| Bundle name | Size | Change |
|---|---|---|
| @signaldb/core | 223.45kB | 240 bytes (0.11%) :arrow_up: |
Affected Assets, Files, and Routes:
view changes for bundle: @signaldb/core
Assets Changed:
| Asset Name | Size Change | Total Size | Change (%) |
|---|---|---|---|
index.cjs2.js |
93 bytes | 31.41kB | 0.3% |
index2.mjs |
93 bytes | 31.21kB | 0.3% |
Collection/index.d.ts |
54 bytes | 14.36kB | 0.38% |
Hi @signalize,
I just reviewed your PR again and noticed that you changed the primary key generator to a beforeInsert hook.
While I appreciate the idea of introducing hooks, I believe implementing only beforeInsert is not sufficient.
If we're adding support for hooks, we should consider the full range of lifecycle events and aim for a more general and consistent implementation.
At this point, I see two options for moving forward with the merge:
- Revert to using the original
primaryKeyGeneratorAPI and introduce hooks more holistically in a future PR. - Fully implement a comprehensive hooks API. To be considered complete, I think the following hooks should be included:
beforeInsertafterInsertbeforeUpdateafterUpdatebeforeReplaceafterReplacebeforeRemoveafterRemove
Let me know which direction you’d prefer to take!
@maxnowack For now, i think it's the best to stick to the 'primaryKeyGenerator' solution. I did some research on the hooks. I think this can be combined with rethinking the 'validate', 'added', 'insert' emits for example.
In case of the insert method:
beforeInsert this.emit('validate', newItem) ....
afterInsert this.emit('added', newItem) this.emit('insert', newItem)
Released in @signaldb/[email protected] 🎉