How to use the @nestjs/typeorm.getConnectionToken function in @nestjs/typeorm

To help you get started, we’ve selected a few @nestjs/typeorm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wix / quix / quix-frontend / service / src / modules / event-sourcing / quix-event-bus.driver.ts View on Github external
getRepositoryToken(DbNotebook),
    );
    const noteRepo: Repository = module.get(getRepositoryToken(DbNote));
    const eventsRepo: Repository = module.get(
      getRepositoryToken(DbAction),
    );
    const fileTreeRepo: FileTreeRepository = module.get(
      getRepositoryToken(FileTreeRepository),
    );
    const folderRepo: Repository = module.get(
      getRepositoryToken(DbFolder),
    );
    const favoritesRepo: Repository = module.get(
      getRepositoryToken(DbFavorites),
    );
    const conn: Connection = module.get(getConnectionToken());
    const configService: ConfigService = module.get(ConfigService);

    return new QuixEventBusDriver(
      eventBus,
      module,
      noteRepo,
      notebookRepo,
      eventsRepo,
      folderRepo,
      fileTreeRepo,
      favoritesRepo,
      conn,
      configService,
      defaultUser,
    );
  }
github nest-cloud / nestcloud / packages / common / utils / provider.util.ts View on Github external
export function getCustomRepository(name: string, repo) {
    const module: typeof TypeormModule = require('@nestjs/typeorm');
    return {
        provide: name,
        useFactory: (connection: Connection) => connection.getCustomRepository(repo),
        inject: [module.getConnectionToken()],
    };
}
github wix / quix / quix-frontend / service / src / app.controller.spec.ts View on Github external
import {Test, TestingModule} from '@nestjs/testing';
import {getConnectionToken} from '@nestjs/typeorm';
import {AppController} from './app.controller';
import {ConfigModule} from './config';
import {ValueProvider} from '@nestjs/common/interfaces';

const fakeConnection = {
  provide: getConnectionToken(),
  useValue: {},
};

describe('AppController', () => {
  let appController: AppController;
  let app: TestingModule | null = null;

  async function preTest(mocked?: ValueProvider) {
    const testingModule = Test.createTestingModule({
      controllers: [AppController],
      providers: [fakeConnection],
      imports: [ConfigModule],
    });
    if (mocked) {
      testingModule.overrideProvider(mocked.provide).useValue(mocked.useValue);
    }
github nest-cloud / nestcloud-consul-starter / src / utils / ProviderUtils.ts View on Github external
export function getRepo(name: string, entity) {
    return {
        provide: name,
        useFactory: (connection: Connection) => connection.getRepository(entity),
        inject: [getConnectionToken()],
    };
}
github ConnextProject / indra / modules / node / src / channel / channel.service.spec.ts View on Github external
beforeAll(async () => {
    module = await Test.createTestingModule({
      imports: [ConfigModule, ChannelModule, CFCoreModule, DatabaseModule],
    })
      .overrideProvider(CFCoreProviderId)
      .useValue(mockCFCoreProvider)
      .compile();

    service = module.get(ChannelService);
    connection = module.get(getConnectionToken());
    channelRepository = connection.getCustomRepository(ChannelRepository);
  });
github nest-cloud / nestcloud-consul-starter / src / utils / ProviderUtils.ts View on Github external
export function getCustomRepo(name: string, repo) {
    return {
        provide: name,
        useFactory: (connection: Connection) => connection.getCustomRepository(repo),
        inject: [getConnectionToken()],
    };
}
github wix / quix / quix-frontend / service / src / modules / web-api / web-api.spec.ts View on Github external
],
      providers: [],
      exports: [],
    }).compile();

    notebookRepo = module.get(getRepositoryToken(DbNotebook));
    noteRepo = module.get(getRepositoryToken(NoteRepository));
    eventsRepo = module.get(getRepositoryToken(DbAction));
    fileTreeRepo = module.get(getRepositoryToken(FileTreeRepository));
    folderRepo = module.get(getRepositoryToken(DbFolder));
    favoritesRepo = module.get(getRepositoryToken(DbFavorites));
    userRepo = module.get(getRepositoryToken(DbUser));
    folderService = module.get(FoldersService);
    notebookService = module.get(NotebookService);
    favoritesService = module.get(FavoritesService);
    conn = module.get(getConnectionToken());
    configService = module.get(ConfigService);
  });
github nest-cloud / nestcloud / packages / common / utils / provider.util.ts View on Github external
export function getRepository(name: string, entity) {
    const module: typeof TypeormModule = require('@nestjs/typeorm');
    return {
        provide: name,
        useFactory: (connection: Connection) => connection.getRepository(entity),
        inject: [module.getConnectionToken()],
    };
}