effect-io-ai

Package: effect
Module: PrimaryKey

PrimaryKey.value

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"

Signature

declare const value: (self: PrimaryKey) => string

Source

Since v2.0.0