Observed since 20 Oct, 22:16 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Typescript library for working with DynamoDB tables
This repository provides a library to work with DynamoDB tables.
Get started quickly by following the instructions below.
Use NPM to install this library into your project:
npm install --save @0to10/aws-dynamodb
Implementing a repository is easy. Create a new class and extend the abstract Repository class
that the library exposes.
After implementing the abstract hydrate method you can start using the findBy and findOneBy methods
of the repository right away. No additional configuration or methods are needed.
The findBy and findOneBy methods both accept an object of criteria, where the key is the field that
is matched and the value is the value of the field. You may use a wildcard at the end of a value to perform
a "begins_with" search on the DynamoDB table.
The findBy method accepts a second argument to adjust the limit of the query.
'use strict';
import {NativeAttributeValue} from '@aws-sdk/util-dynamodb';
import {Repository} from '@0to10/aws-dynamodb';
class EntityRepository extends Repository<Entity> {
protected hydrate(item: Record<string, NativeAttributeValue>): Entity {
return new Entity(item);
}
}
Any convenience methods may be added to the repository:
In the example below, two methods have been added: findOneByName and findByName. You may choose to
run a custom query by calling the protected query method or call any of the public methods.
'use strict';
import {QueryCommandInput} from '@aws-sdk/client-dynamodb';
import {NativeAttributeValue} from '@aws-sdk/util-dynamodb';
import {Repository} from '@0to10/aws-dynamodb';
class EntityRepository extends Repository<Entity> {
public async findOneByName(name: string): Promise<Entity> {
const params: QueryCommandInput = {
// Define your search params
};
return this.query(params);
}
public async findByName(name: string): Promise<Entity[]> {
return this.findBy({
name_field: name,
});
}
protected hydrate(item: Record<string, NativeAttributeValue>): Entity {
return new Entity(item);
}
}
When using and implementing a Repository class, please note:
hydrate method must always return a single hydrated documentfindOneBy method will always return a single entity or undefined if no result was foundfindBy method always returns an array of entities (which may be empty)You may typehint for an Array-like return when using the findBy method, but be aware that the actual
return type is a Collection (which extends Array). The Collection class exposes a LastEvaluatedKey
variable with which you can run consecutive queries for when you need more results than the specified
limit.
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 22:16 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:cf4cc0f88a81dab773c7bbc65aebd4cb2f97b118cf1b06a03b6d53695d296c17