feat: add optional prefix parameter to nanoid() for typed ids #18#29
feat: add optional prefix parameter to nanoid() for typed ids #18#29nik-sta wants to merge 2 commits into
Conversation
23364e1 to
080212a
Compare
eae4459 to
fd629d4
Compare
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe ChangesNanoid prefix support
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…rough #18 The signature change (new prefix parameter) means the old nanoid(int, text, float) must be dropped; a dependent column default now causes an atomic rollback with recovery steps in the README instead of leaving two ambiguous nanoid functions behind. Adds tests for out-of-alphabet prefix characters and mixed positional/named notation.
080212a to
b9c3b58
Compare
6e7a3e8 to
681163e
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. You're currently rate limited under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. Your next review will be available in 8 minutes. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
Summary
Adds
prefix text DEFAULT ''as the new last parameter ofnanoid(), prepended to the generated id for Stripe-style typed ids (usr_,ord_, ...):sizekeeps meaning the number of random symbols; the total id length islength(prefix) + size, so columns must be sized accordingly (e.g.char(25)fornanoid(prefix => 'usr_'))NULLprefix behaves like an empty prefix instead of producing aNULLid (coalesce(prefix, ''))nanoid_optimized()stays unchanged; the prefix is concatenated innanoid()nanoid(int, text, float)is dropped on upgrade, as the install script already does todayCREATE TABLEexampleStacked on #24; the diff of this PR is the prefix commit only.
Verification
nanoid(prefix => 'ord_'), andNULLprefix;SELECT nanoid()behavior is unchanged (21 characters, default alphabet)nanoid(size, alphabet, additionalBytesFactor, prefix)signatureCredits
Idea by @abdirahmn1.
Closes #18
Summary by CodeRabbit
New Features
prefixparameter to generated Nano IDs, supporting typed identifiers such asusr_andord_.Bug Fixes
NULLprefix now behaves like no prefix (no longer yields aNULLidentifier).Documentation
NULLprefix behavior.Tests