Gathering detailed insights and metrics for nest-dynamodb-toolbox
Gathering detailed insights and metrics for nest-dynamodb-toolbox
Gathering detailed insights and metrics for nest-dynamodb-toolbox
Gathering detailed insights and metrics for nest-dynamodb-toolbox
npm install nest-dynamodb-toolbox
Typescript
Module System
Node Version
NPM Version
52.1
Supply Chain
95.3
Quality
74.6
Maintenance
50
Vulnerability
99.6
License
TypeScript (95.84%)
JavaScript (4.16%)
Total Downloads
400
Last Day
2
Last Week
4
Last Month
6
Last Year
74
37 Commits
2 Forks
2 Watching
6 Branches
1 Contributors
Latest Version
0.0.2
Package Id
nest-dynamodb-toolbox@0.0.2
Unpacked Size
131.13 kB
Size
37.06 kB
File Count
22
NPM Version
8.5.5
Node Version
16.15.0
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
300%
4
Compared to previous week
Last month
100%
6
Compared to previous month
Last year
-33.9%
74
Compared to previous year
5
28
A progressive Node.js framework for building efficient and scalable server-side applications.
dynamodb-toolbox module for Nest.
1$ npm install --save nest-dynamodb-toobox dynamodb-toolbox aws-sdk
A AWS NestJS Starter project has been created to demo the usage of this library.
1. Add import into your app module
src/app.module.ts
1import { DynamoDBToolboxModule } from "nest-dynamodb-toolbox"; 2import { UserModule } from "./user/user.module"; 3import { DynamoDB } from 'aws-sdk' 4 5@Module({ 6 imports: [ 7 UserModule, 8 DynamoDBToolboxModule.forRoot({ 9 DocumentClient: new DynamoDB.DocumentClient({ 10 endpoint: "http://localhost:4567", 11 region: "us-east-1", 12 credentials: { 13 accessKeyId: "test", 14 secretAccessKey: "test" 15 } 16 }), 17 name: "test-table", 18 partitionKey: "pk", 19 sortKey: "sk" 20 }), 21 ], 22}) 23export class AppModule {
Check here for forRoot()
definition.
There is also forRootAsync(options: DynamoDBToolboxModuleAsyncOptions)
if you want to use a factory with dependency injection.
2. Create a schema
src/user/user.schema.ts
1import { Entity } from "dynamodb-toolbox"; 2 3export const UserEntity = new Entity<User>({ 4 name: 'User', 5 attributes: { 6 pk: { partitionKey: true }, 7 sk: { sortKey: true }, 8 name: { 9 type: "string" 10 } 11 }, 12 //table not needed 13}); 14 15export interface User { 16 pk: string, 17 sk: string, 18 name: string 19} 20
3. Add the entities you want to inject to your modules
This can be a feature module (as shown below) or within the root AppModule next to DynamoDBToolboxModule.forRoot()
.
src/user/user.module.ts
1import { DynamoDBToolboxModule } from 'nest-dynamodb-toolbox'; 2import { UserEntity } from './user.entity'; 3import { UserService } from './user.service'; 4 5@Module({ 6 imports: [ 7 DynamoDBToolboxModule.forFeature([UserSchema ]), 8 ], 9 providers: [ 10 UserService, 11 ... 12 ], 13}) 14export class UserModule {}
There is also forFeatureAsync(factories?: AsyncEntityFactory[])
if you want to use a factory with dependency injection.
4. Inject and use your entity
src/user/user.service.ts
1import { Injectable } from '@nestjs/common'; 2import { InjectEntity } from 'nest-dynamodb-toolbox'; 3import { UserEntity } from './user.interface'; 4 5@Injectable() 6export class UserService { 7 constructor( 8 @InjectEntity(UserEntity.name) 9 private userEntity: typeof UserEntity, 10 ) {} 11 12 create(user) { 13 return this.userEntity.put(user); 14 } 15 16 update(id, user) { 17 return this.userEntity.update({ 18 ...user 19 sk : id, 20 pk : id, 21 }); 22 } 23 24 async getAll() { 25 return await this.entity.scan(); 26 } 27 28 async get(id: string) { 29 return await this.entity.get({ 30 pk: id, 31 sk: id 32 }); 33 } 34}
5. Injecting Table class instance
1import { Injectable } from '@nestjs/common'; 2import { InjectEntity, InjectTable } from 'nest-dynamodb-toolbox'; 3import { UserEntity } from './user.interface'; 4import { Table } from "dynamodb-toolbox"; 5 6@Injectable() 7export class UserService { 8 constructor( 9 @InjectTable() 10 private table: Table, 11 @InjectEntity(UserEntity.name) 12 private userEntity: typeof UserEntity, 13 ) {} 14 15 async transaction() { 16 return await this.table.transactWrite([ 17 this.entity.putTransaction({ 18 pk: randomId, 19 sk: randomId, 20 name: e, 21 }), 22 this.entity.putTransaction({ 23 pk: randomId, 24 sk: randomId, 25 name: e, 26 }) 27 ]) 28 } 29}
No vulnerabilities found.
No security vulnerabilities found.