Page Contents

Home > @loopback/repository > RepositoryMixin

RepositoryMixin() function

A mixin class for Application that creates a .repository() function to register a repository automatically. Also overrides component function to allow it to register repositories automatically.

Signature:

export declare function RepositoryMixin<T extends Class<any>>(superClass: T): {
    new (...args: any[]): {
        [x: string]: any;
        repository<R extends Repository<any>>(repoClass: Class<R>, name?: string | undefined): Binding<R>;
        getRepository<R extends Repository<any>>(repo: Class<R>): Promise<R>;
        dataSource<D extends juggler.DataSource>(dataSource: D | Class<D>, name?: string | undefined): Binding<D>;
        component(component: Class<unknown>, name?: string | undefined): void;
        mountComponentRepositories(component: Class<unknown>): void;
        migrateSchema(options?: SchemaMigrationOptions): Promise<void>;
    };
} & T;

Parameters

Parameter Type Description
superClass T  

Returns:

{ new (...args: any[]): { [x: string]: any; repository<R extends Repository<any>>(repoClass: Class<R>, name?: string | undefined): Binding<R>; getRepository<R extends Repository<any>>(repo: Class<R>): Promise<R>; dataSource<D extends juggler.DataSource>(dataSource: D | Class<D>, name?: string | undefined): Binding<D>; component(component: Class<unknown>, name?: string | undefined): void; mountComponentRepositories(component: Class<unknown>): void; migrateSchema(options?: SchemaMigrationOptions): Promise<void>; }; } & T

Example

class MyApplication extends RepositoryMixin(Application) {}

Please note: the members in the mixin function are documented in a dummy class called RepositoryMixinDoc