[Feature Request] nanoid support custom alphabet
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #2377 by @sanny-io — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- sqlite, typescript
- Domain
- databases
Research direction
The request is to let @default(nanoid(16)) in the ZenStack schema draw from a user-supplied alphabet, configured via a new option on ZenStackClient (shown next to SqliteDialect in the body). Start by locating where the nanoid default is resolved and where client options are declared, then thread a nanoidCustomAlphabet value through to the ID generator so existing nanoid(n) usage keeps working. Done means the schema default honors the configured alphabet and the behaviour is covered by a test; note that a linked pull request (#2377) was closed unmerged and the thread has been silent for months, so confirm the desired API with maintainers before starting.
Written by the indexing model from the issue text.
Description
Most of the time, we need to define a special business ID field for models, such as post_id or user_id. We often choose UUID or nanoid for generating these IDs. However, when using nanoid, we found that it cannot meet our requirements because it defaults to generating IDs with uppercase letters and numbers. Sometimes we prefer IDs in lowercase letters and numbers, which nanoid cannot handle. As a result, we are forced to set the ID field as non‑nullable and generate a compliant ID in the code layer when creating records.
This is not an ideal practice. Providing a custom alphabet feature for nanoid would help reduce this mental overhead. Moreover, I believe the optimal API design would be:
-
Keep the usage as is:
@default(nanoid(16)) -
Add an optional parameter when creating the client:
export const db = new ZenStackClient(schema, {
dialect: new SqliteDialect({
database: new SQLite(':memory:'),
}),
nanoidCustomAlphabet: "1234567890abcdef"
});
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 157
- Avg merge
- 11h 42m
- Merged PRs (30d)
- 20
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from zenstackhq/zenstack
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
zenstackhq/zenstack#2873 ·
Maintainers usually reply within 1 day
-
runtime
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zenstackhq/zenstack#2868 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
zenstackhq/zenstack#2694 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
zenstackhq/zenstack#2659 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
zenstackhq/zenstack#2542 · 1 comment ·
Maintainers usually reply within 1 day
All issues in zenstackhq/zenstack
Similar issues
-
by: ai-assisted frontend good-for: new-member spike
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Northeastern-Electric-Racing/Argos#847 ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
SignalK/freeboard-sk#990 ·
Maintainers usually reply within 1 day
-
[missing-inheritance] audit review (1 preset)Possibly taken @github-actions claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 82/100
osmberlin/tagging-schema-browser#363 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Albert-Weasker/niubigeo#205 ·
Maintainers usually reply within 1 day
-
area/frontend area/v2 kind/bug priority/needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
kubeflow/notebooks#1498 · 1 comment ·
Maintainers usually reply within 1 day