Custom ID generation function #6

Open
opened 2026-08-01 21:34:51 +02:00 by c.fahner · 0 comments
Owner

During development of #1 three IdGenerator's have been declared: None, Sequence and UniqueIdentifier.

A fourth case CustomFunction should be added. The custom function itself would be declared as a property on the #[IdOptions] attribute with the following signature: pure-Closure(Document):string, where the Document is the document to be inserted. The Document should be a read-only wrapper of the actual document being inserted.

The knowledge on how to generate an ID is specific to each Entity and should therefore be part of the ORM attributes in the same class. It should not be delegated to the application/framework.

Two use-cases for custom ID functions have been encountered (so far) by me personally:

  • Generating an ID that is a secure random token, to make guessing it impossible
  • Generating an ID that is a safe/escaped variant of a user-supplied field value
During development of #1 three `IdGenerator`'s have been declared: `None`, `Sequence` and `UniqueIdentifier`. A fourth case `CustomFunction` should be added. The custom function itself would be declared as a property on the `#[IdOptions]` attribute with the following signature: `pure-Closure(Document):string`, where the `Document` is the document to be inserted. The `Document` should be a read-only wrapper of the actual document being inserted. The knowledge on how to generate an ID is specific to each `Entity` and should therefore be part of the ORM attributes in the same class. It should not be delegated to the application/framework. Two use-cases for custom ID functions have been encountered (so far) by me personally: * Generating an ID that is a secure random token, to make guessing it impossible * Generating an ID that is a safe/escaped variant of a user-supplied field value
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
slendium/ocd#6
No description provided.