idb-ts
    Preparing search index...

    Function CompositeKeyPath

    • Class decorator that defines a composite primary key spanning multiple fields. Use this when the entity's identity is determined by a combination of fields rather than a single property.

      Parameters

      • fields: string[]

        An ordered array of field names that together form the key.

      • Optionaloptions: KeyPathOptions

        Optional key path configuration. Key generation is not supported for composite keys: passing generator or autoIncrement throws immediately at decoration time instead of being silently ignored.

      Returns ClassDecorator

      @CompositeKeyPath must execute before @DataClass. Decorators are applied bottom-up, so write it below @DataClass (closer to the class keyword). @KeyPath must not also be used on the same class.

      Error - At decoration time when options.generator or options.autoIncrement is provided.

      @DataClass()
      @CompositeKeyPath(['userId', 'projectId'])
      class UserProject {
      userId!: string;
      projectId!: string;
      role!: string;
      }

      // Read by composite key:
      const rel = await db.UserProject.read(['user1', 'proj42']);