npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tresdoce-nestjs-toolkit/dynamoose

v2.0.12

Published

Tresdoce NestJS Toolkit - Módulo de base de datos DynamoDB - Dynamoose

Readme

Este módulo está pensado para ser utilizado en NestJS Starter, o cualquier proyecto que utilice una configuración centralizada, siguiendo la misma arquitectura del starter.

Glosario


📝 Requerimientos básicos

🛠️ Instalar dependencia

npm install -S @tresdoce-nestjs-toolkit/dynamoose
yarn add @tresdoce-nestjs-toolkit/dynamoose

⚙️ Configuración

Agregar los datos de conexión a DynamoDB en configuration.ts utilizando el key dynamodb y que contenga el objeto con los datos conexión desde las variables de entorno.

//./src/config/configuration.ts
import { Typings } from '@tresdoce-nestjs-toolkit/core';
import { registerAs } from '@nestjs/config';
import * as PACKAGE_JSON from '../../package.json';

export default registerAs('config', (): Typings.AppConfig => {
  return {
    //...
    dynamodb: {
      local: process.env.NODE_ENV !== 'production' || false,
      logger: process.env.NODE_ENV !== 'production' || false,
      aws: {
        accessKeyId: `${process.env.AWS_ACCESS_KEY_ID}`,
        secretAccessKey: `${process.env.AWS_SECRET_ACCESS_KEY}`,
        region: `${process.env.AWS_REGION}`,
      },
      table: {
        create: process.env.NODE_ENV !== 'production' || false,
        prefix: `${PACKAGE_JSON.name}-`,
        suffix: '-table',
      },
    },
    //...
  };
});

local: Habilita el uso de DynamoDB de manera local.

  • Type: Boolean | String
  • Default: false
  • Values: true | false | http://docker:8000 | http://localhost:8000

logger: Habilita los logs utilizando como provider a dynamoose-logger.

  • Type: Boolean
  • Default: false

AWS

Para los datos de AWS es sumamente importante utilizar los siguientes nombres de variables de entorno: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION

accessKeyId: Es el Access Key ID de aws.

  • Type: String
  • Default: local

secretAccessKey: Es el Secret Access Key de aws.

  • Type: String
  • Default: local

region: Es la region de la cuenta de aws.

  • Type: String
  • Default: us-east-1

Table

Esta propiedad solo está pensada para el desarrollo local, ya que para los entornos de AWS se recomienda no utilizarlo.

create: Activa la creación de la tabla en DynamoDB en caso de que no exista.

  • Type: Boolean
  • Default: true

prefix: Es una cadena de texto que se antepone al nombre de la tabla.

  • Type: String

suffix: Es una cadena de texto que se agrega al final del nombre de la tabla.

  • Type: String

💬 Para más información sobre la configuración de este módulo puedes revisar la Documentación de Dynamoose.

👨‍💻 Uso

Importar el DynamooseModule en el archivo app.module.ts, y el módulo se encargará de obtener la configuración e instanciar la conexión.

//./src/app.module.ts
import { DynamooseModule } from '@tresdoce-nestjs-toolkit/dynamoose';

@Module({
  //...
  imports: [
    //...
    DynamooseModule,
    //...
  ],
  //...
})
export class AppModule {}

Crear el Schema

//./src/users/models/user.schema.ts
import { Schema } from 'dynamoose';

export const UserSchema = new Schema({
  id: {
    type: String,
    hashKey: true,
  },
  firstName: {
    type: String,
  },
  lastName: {
    type: String,
  },
  email: {
    type: String,
  },
});

Crear el interface del Model

//./src/users/interfaces/user.interface.ts
export interface UserKey {
  id: string;
}

export interface User extends UserKey {
  firstName: string;
  lastName: string;
  email: string;
}

UserKey contiene la hashKey/partitionKey y (opcionalmente) la rangeKey/sortKey. User contiene todos los atributos del document/item. Al crear estas dos interfaces y usarlas al inyectar tu modelo tendrás typechecking al usar operaciones como Model.update().

Inyectar los Schemas al módulo

Se puede inyectar a nivel global en el app.module.ts, o bien, en los módulos que requieran utilizar dicho modelo.

//./src/users/users.module.ts
import { Module } from '@nestjs/common';
import { DynamooseModule } from '@tresdoce-nestjs-toolkit/dynamoose';

import { UsersController } from './controllers/users.controller';
import { UsersService } from './services/users.service';
import { UserSchema } from './models/user.schema';

@Module({
  imports: [
    DynamooseModule.forFeature([
      {
        name: 'User',
        schema: UserSchema,
        options: {
          tableName: 'user',
        },
      },
    ]),
  ],
  controllers: [UsersController],
  providers: [UsersService],
})
export class UsersModule {}

Inyectar y usar los Models el módulo

//./src/users/users.service.ts
import { Injectable } from '@nestjs/common';
import { InjectModel, Model } from '@tresdoce-nestjs-toolkit/dynamoose';

import { UserKey, User as IUser } from '../interfaces/user.interface';

@Injectable()
export class UsersService {
  constructor(@InjectModel('User') private userModel: Model<IUser, UserKey>) {}

  async create(user: User): Promise<any> {
    return await this.userModel.create(user);
  }

  async update(key: UserKey, user: Partial<User>): Promise<any> {
    return await this.userModel.update(key, user);
  }

  async findOne(key: UserKey): Promise<any> {
    return await this.userModel.get(key);
  }

  async findAll(): Promise<any> {
    return await this.userModel.scan().exec();
  }
}

Transaction

//./src/users/users.service.ts
import { Injectable } from '@nestjs/common';
import { InjectModel, Model, TransactionSupport } from '@tresdoce-nestjs-toolkit/dynamoose';

import { UserKey, User as IUser } from '../interfaces/user.interface';

@Injectable()
export class UsersService {
  constructor(@InjectModel('User') private userModel: Model<IUser, UserKey>) {
    super();
  }

  async create(user: User): Promise<any> {
    await this.transaction([
      this.userModel.transaction.create(user);
    ]);
  }
}

💬 Este módulo usa como dependencia inyectada a Dynamoose, para obtener más información sobre su uso podés consultar su documentación.

📄 Changelog

Todos los cambios notables de este paquete se documentarán en el archivo Changelog.