signaldb icon indicating copy to clipboard operation
signaldb copied to clipboard

feat: custom primary key generator

Open signalize opened this issue 8 months ago • 3 comments

New feature! Custom generator for primary key.

signalize avatar Apr 09 '25 14:04 signalize

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.

codecov[bot] avatar Apr 09 '25 14:04 codecov[bot]

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%

codecov[bot] avatar Apr 09 '25 15:04 codecov[bot]

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:

  1. Revert to using the original primaryKeyGenerator API and introduce hooks more holistically in a future PR.
  2. Fully implement a comprehensive hooks API. To be considered complete, I think the following hooks should be included:
    • beforeInsert
    • afterInsert
    • beforeUpdate
    • afterUpdate
    • beforeReplace
    • afterReplace
    • beforeRemove
    • afterRemove

Let me know which direction you’d prefer to take!

maxnowack avatar Apr 24 '25 06:04 maxnowack

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

signalize avatar May 07 '25 11:05 signalize

Released in @signaldb/[email protected] 🎉

maxnowack avatar May 12 '25 07:05 maxnowack