iBet uBet web content aggregator. Adding the entire web to your favor.
iBet uBet web content aggregator. Adding the entire web to your favor.



Link to original content: https://npmjs.com/package/@atls/nestjs-dataloader
@atls/nestjs-dataloader - npm

@atls/nestjs-dataloader
TypeScript icon, indicating that this package has built-in type declarations

0.0.10 • Public • Published

Установка

yarn add @atls/nestjs-dataloader

Использование

  1. Импортируйте DataLoaderModule в ваш модуль:
import { DataLoaderModule } from '@atls/nestjs-dataloader'

@Module({
  imports: [DataLoaderModule],
})
export class AppModule {}
  1. Создайте свой кастомный DataLoader:
import * as DataLoader from 'dataloader'
import { Injectable }  from '@nestjs/common'
@Injectable()
export class MyDataLoader extends DataLoader<string, string> {
  constructor() {
    super(async (keys: string[]) => {
      / Ваш код для загрузки данных пачками
    })
  }
}
  1. Зарегистрируйте ваш DataLoader в провайдерах:
import { MyDataLoader } from './my-dataloader'

@Module({
  providers: [MyDataLoader],
})
export class AppModule {}
  1. Инжектируйте DataLoader в резолверы и сервисы:
import { MyDataLoader } from './my-dataloader'

@Injectable()
export class MyService {
  constructor(private readonly dataLoader: MyDataLoader) {}

  async getData(key: string) {
    return this.dataLoader.load(key)
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @atls/nestjs-dataloader

Weekly Downloads

3

Version

0.0.10

License

BSD-3-Clause

Unpacked Size

7.65 kB

Total Files

20

Last publish

Collaborators

  • torinasakura
  • tfk70