@nestjs/typeorm

  • Version 12.0.3
  • Published
  • 42 kB
  • No dependencies
  • MIT license

Install

npm i @nestjs/typeorm
yarn add @nestjs/typeorm
pnpm add @nestjs/typeorm

Overview

TypeORM for NestJS: connections and repositories through dependency injection, entities, transactions and multiple databases.

Index

Variables

variable getConnectionToken

const getConnectionToken: (dataSource?: any) => any;
  • Deprecated

Functions

function generateString

generateString: () => string;

    function getCustomRepositoryToken

    getCustomRepositoryToken: (repository: Function) => string;
    • This function generates an injection token for an Entity or Repository

      Parameter This

      parameter can either be an Entity or Repository

      Returns

      {string} The Repository injection token

    function getDataSourceName

    getDataSourceName: (dataSource?: DataSourceRef | { name?: string }) => string;
    • This function returns the DataSource name for the given DataSource, DataSourceOptions or dataSource name. TypeORM v1 removed name from DataSource and DataSourceOptions, so it is read defensively while remaining backward compatible with 0.3.x (where the user-supplied options still carry it).

      Parameter dataSource

      This optional parameter is either a DataSource, or a DataSourceOptions or a string.

      Returns

      {string} The DataSource name, or 'default' when no name is set.

    function getDataSourcePrefix

    getDataSourcePrefix: (dataSource?: DataSourceRef) => string;
    • This function returns a DataSource prefix based on the dataSource name

      Parameter dataSource

      This optional parameter is either a DataSource, or a DataSourceOptions or a string.

      Returns

      {string | Function} The DataSource injection token.

    function getDataSourceToken

    getDataSourceToken: (
    dataSource?: DataSourceRef
    ) => string | Function | Type<DataSource>;
    • This function returns a DataSource injection token for the given DataSource, DataSourceOptions or dataSource name.

      Parameter dataSource

      This optional parameter is either a DataSource, or a DataSourceOptions or a string.

      Returns

      {string | Function} The DataSource injection token.

    function getEntityManagerToken

    getEntityManagerToken: (dataSource?: DataSourceRef) => string | Function;
    • This function returns an EntityManager injection token for the given DataSource, DataSourceOptions or dataSource name.

      Parameter dataSource

      This optional parameter is either a DataSource, or a DataSourceOptions or a string.

      Returns

      {string | Function} The EntityManager injection token.

    function getRepositoryToken

    getRepositoryToken: (
    entity: EntityClassOrSchema,
    dataSource?: DataSourceRef
    ) => Function | string;
    • This function generates an injection token for an Entity or Repository

      Parameter entity

      parameter can either be an Entity or Repository

      Parameter dataSource

      This optional parameter is either a DataSource, or a DataSourceOptions or a string.

      Returns

      {string} The Entity | Repository injection token

    function handleRetry

    handleRetry: (
    retryAttempts?: number,
    retryDelay?: number,
    dataSourceName?: string,
    verboseRetryLog?: boolean,
    toRetry?: (err: any) => boolean
    ) => <T>(source: Observable<T>) => Observable<T>;

      function InjectConnection

      InjectConnection: (dataSource?: DataSourceRef) => ReturnType<typeof Inject>;
      • Deprecated

      function InjectDataSource

      InjectDataSource: (dataSource?: DataSourceRef) => ReturnType<typeof Inject>;

      function InjectEntityManager

      InjectEntityManager: (dataSource?: DataSourceRef) => ReturnType<typeof Inject>;

      function InjectRepository

      InjectRepository: (
      entity: EntityClassOrSchema,
      dataSource?: DataSourceRef
      ) => ReturnType<typeof Inject>;

      Classes

      class DuplicateDataSourceException

      class DuplicateDataSourceException extends Error {}

        constructor

        constructor(dataSourceName: string);

          class TypeOrmModule

          class TypeOrmModule {}

          method forFeature

          static forFeature: (
          entities?: EntityClassOrSchema[],
          dataSource?: DataSourceRef
          ) => DynamicModule;

            method forRoot

            static forRoot: (options?: TypeOrmModuleOptions, name?: string) => DynamicModule;
            • Registers the TypeORM module with the given options.

              Parameter options

              The TypeORM data source options.

              Parameter name

              Optional data source name. When provided, it overrides options.name (if any) so the data source name can be configured separately from the connection options – mirroring forRootAsync.

            method forRootAsync

            static forRootAsync: (options: TypeOrmModuleAsyncOptions) => DynamicModule;

              Interfaces

              interface TypeOrmModuleAsyncOptions

              interface TypeOrmModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {}

              property dataSourceFactory

              dataSourceFactory?: TypeOrmDataSourceFactory;

                property extraProviders

                extraProviders?: Provider[];

                  property inject

                  inject?: any[];

                    property name

                    name?: string;

                      property useClass

                      useClass?: Type<TypeOrmOptionsFactory>;

                        property useExisting

                        useExisting?: Type<TypeOrmOptionsFactory>;

                          property useFactory

                          useFactory?: (
                          ...args: any[]
                          ) => Promise<TypeOrmModuleOptions> | TypeOrmModuleOptions;

                            interface TypeOrmOptionsFactory

                            interface TypeOrmOptionsFactory {}

                            method createTypeOrmOptions

                            createTypeOrmOptions: (
                            connectionName?: string
                            ) => Promise<TypeOrmModuleOptions> | TypeOrmModuleOptions;

                              Type Aliases

                              type TypeOrmDataSourceFactory

                              type TypeOrmDataSourceFactory = (options?: DataSourceOptions) => Promise<DataSource>;

                              type TypeOrmModuleOptions

                              type TypeOrmModuleOptions = {
                              /**
                              * NestJS-level datasource identifier.
                              * In TypeORM 0.3.x this also existed on DataSourceOptions; in 1.0 it was removed.
                              */
                              name?: string;
                              /**
                              * Maximum number of connection attempts, including the first one
                              * Default: 10
                              */
                              retryAttempts?: number;
                              /**
                              * Delay between connection retry attempts (ms)
                              * Default: 3000
                              */
                              retryDelay?: number;
                              /**
                              * Function that determines whether the module should
                              * attempt to connect upon failure.
                              *
                              * @param err error that was thrown
                              * @returns whether to retry connection or not
                              */
                              toRetry?: (err: any) => boolean;
                              /**
                              * If `true`, entities will be loaded automatically.
                              */
                              autoLoadEntities?: boolean;
                              /**
                              * If `true`, will show verbose error messages on each connection retry.
                              */
                              verboseRetryLog?: boolean;
                              /**
                              * If `true` database initialization will not be performed during module initialization.
                              * This means that database connection will not be established and migrations will not run.
                              * Database initialization will have to be performed manually using `DataSource.initialize`
                              * and it will have to implement own retry mechanism (if necessary).
                              */
                              manualInitialization?: boolean;
                              } & Partial<DataSourceOptions>;

                              Package Files (6)

                              Dependencies (0)

                              No dependencies.

                              Dev Dependencies (21)

                              Peer Dependencies (5)

                              Badge

                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@nestjs/typeorm.

                              • Markdown
                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@nestjs/typeorm)
                              • HTML
                                <a href="https://www.jsdocs.io/package/@nestjs/typeorm"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>