Hyperlinkv0.8.0-beta.28

PrimaryKey

PrimaryKey.valueconsteffect/PrimaryKey.ts:123
(self: PrimaryKey): string

Extracts the string value from a PrimaryKey.

When to use

Use to read the stable string identifier from a value that implements PrimaryKey.

Example (Reading primary key values)

import { PrimaryKey } from "effect"

class OrderId implements PrimaryKey.PrimaryKey {
  constructor(private timestamp: number, private sequence: number) {}

  [PrimaryKey.symbol](): string {
    return `order_${this.timestamp}_${this.sequence}`
  }
}

const orderId = new OrderId(1640995200000, 1)
console.log(PrimaryKey.value(orderId)) // "order_1640995200000_1"

// Can also be used with simple string-based implementations
const simpleKey = {
  [PrimaryKey.symbol]: () => "simple-key-123"
}
console.log(PrimaryKey.value(simpleKey)) // "simple-key-123"
accessors
export const value = (self: PrimaryKey): string => self[symbol]()
Referenced by 3 symbols