PrimaryKeyAn interface for objects that can provide a string-based primary key.
When to use
Use to define values that expose a stable string identifier for equality, hashing, caching, or persistence.
Details
Objects implementing this interface must provide a method that returns a unique string identifier.
Example (Implementing a primary key)
import { PrimaryKey } from "effect"
class ProductId implements PrimaryKey.PrimaryKey {
constructor(private category: string, private id: number) {}
[PrimaryKey.symbol](): string {
return `${this.category}-${this.id}`
}
}
const productId = new ProductId("electronics", 42)
console.log(PrimaryKey.value(productId)) // "electronics-42"models
Source effect/PrimaryKey.ts:623 lines
export interface PrimaryKey {
[const symbol: "~effect/interfaces/PrimaryKey"Defines the unique identifier used to identify objects that implement the PrimaryKey interface.
When to use
Use to implement the PrimaryKey protocol as a computed property key on
classes or object literals that expose a stable string identifier.
symbol](): string
}Referenced by 10 symbols