Function Entity

  • A class decorator for marking a class as an entity within the context of the ORM system. This decorator is essential for registering the class as a distinct entity in the ORM's metadata system, enabling the ORM to recognize and manage instances of this class as part of its data model. By designating classes as entities, it facilitates their integration into the ORM framework, allowing for operations such as querying, persisting, and managing relationships between entities.

    IMPORTANT - All entity classes should extend a table class decorated by Table

    Entities MUST declare their type property as a string literal matching the class name. This enables compile-time type safety for query filters and return types.

    Type Parameters

    • C extends new (...args: never[]) => default

      The constructor of the class being decorated. The class must extend DynaRecord and declare readonly type as a string literal (e.g., declare readonly type: "Order").

    Parameters

    • target: C & (
          string extends InstanceType<C>["type"]
              ? {
                  __entityTypeError: "Entity must declare: declare readonly type: \"ClassName\"";
              }
              : unknown
      )

      The constructor function of the class being decorated.

    • _context: ClassDecoratorContext<C>

    Returns void

    The decorator does not return a value.

    Usage example:

    @Entity
    class User extends MyTable {
    declare readonly type: "User";
    // User entity implementation
    }