@nest-dynamodb/typedorm
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Nest Logo

A DynamoDB module for Nest framework (node.js) using typeDorm library

Github action

Installation

with npm

npm install --save @nest-dynamodb/typedorm

with yarn

yarn add @nest-dynamodb/typedorm

How to use?

TypeDormModule.forRoot(options)

import { Module } from '@nestjs/common';
import { TypeDormModule } from '@nest-dynamodb/typedorm';
import { AppController } from './app.controller';
@Module({
  imports: [
    TypeDormModule.forRoot({
        table,
        entities: [],
        documentClient: new DocumentClientV3(new DynamoDBClient({})),
        name: instanceName
      }),
  ],
  controllers: [AppController],
})
export class AppModule {}

TypeDormModule.forRootAsync(options)

import { Module } from '@nestjs/common';
import { TypeDormModule } from '@nest-dynamodb/typedorm';
import { AppController } from './app.controller';
@Module({
  imports: [
    TypeDormModule.forRootAsync({
        // need another name here for dependency injection, @InjectTypeDorm(instanceName)
        name: instanceName,
        useFactory: async () => {
          return {
            table,
            entities: [],
            documentClient: new DocumentClientV3(new DynamoDBClient({})),
            name: instanceName
          }
        },
      }),
  ],
  controllers: [AppController],
})
export class AppModule {}

InjectTypeDorm(name?)

import { Controller, Get, } from '@nestjs/common';
import { InjectTypeDorm, TypeDormConnection } from '@nest-dynamodb/typedorm';
@Controller()
export class AppController {
  constructor(
    @InjectTypeDorm() private readonly connection: TypeDormConnection,
  ) {}
  @Get()
  async getHello() {
    const item = await this.connection.entityManager.findOne(...);
    return { item };
  }
}

TypeDormModule.forRootNonInjection(options)

import { Module } from '@nestjs/common';
import { TypeDormModule } from '@nest-dynamodb/typedorm';
import { AppController } from './app.controller';
@Module({
  imports: [
    TypeDormModule.forRootNonInjection({
        table,
        entities: [],
        documentClient: new DocumentClientV3(new DynamoDBClient({})),
      }),
  ],
  controllers: [AppController],
})
export class AppModule {}
import { Controller, Get, } from '@nestjs/common';
import { TypeDormConnection } from '@nest-dynamodb/typedorm';
@Controller()
export class AppController {
  constructor(
    // do not need InjectTypeDorm here
    private readonly connection: TypeDormConnection,
  ) {}
  @Get()
  async getHello() {
    const item = await this.connection.entityManager.findOne(...);
    return { item };
  }
}

License

MIT

Package Sidebar

Install

npm i @nest-dynamodb/typedorm

Weekly Downloads

384

Version

1.1.0

License

MIT

Unpacked Size

17.7 kB

Total Files

20

Last publish

Collaborators

  • felix-chan