idb-ts
    Preparing search index...

    Function RetentionPolicy

    • Class decorator that configures an automatic data retention policy for the entity. When one or more entities define a retention policy, the Database runs a background cleanup job that periodically deletes expired records.

      Parameters

      Returns ClassDecorator

      Error - At decoration time if options.seconds is not a positive integer.

      The cleanup interval is derived from the GCD of all registered seconds values, ensuring the job runs as infrequently as possible while still honouring every policy. The job uses a cursor-based readwrite transaction and emits debug-level log messages on each tick.

      @RetentionPolicy({ seconds: 60 * 60 * 24 * 30 }) // 30-day retention
      @DataClass()
      class Session {
      @KeyPath()
      id!: string;
      userId!: string;
      }