@banxware/simple-repository
v2.5.0
Published
A simple repository implementation for DynamoDB and S3
Downloads
477
Maintainers
Keywords
Readme
Simple Repository
Install
$ npm i @banxware/simple-repository
Usage
Dynamo Repository
type User {
id: string
firstName: string
lastName: string
active: boolean
}
class UserRepository extends SimpleDynamoRepository<User> {
async findActiveUsersByName(name: string): Promise<User> {
return await this.findByQuery({
IndexName: 'name',
KeyConditionExpression: 'name = :name AND active = :active',
ExpressionAttributeValues: {
':name': name,
':active': true,
},
})
}
}
const userRepository = new UserRepository(new DynamoDBClient({ region: 'eu-central-1' }), 'users')
userRepository.save({ id: 'uuid', firstName: 'john', lastName: 'doe', active: true })
userRepository.save({ id: 'uuid2', firstName: 'john', lastName: 'travolta', active: false })
userRepository.findOne('uuid')
userRepository.findActiveUsersByName('john')
userRepository.findAll()
S3 Repository
type File {
key: string
content: Uint8Array | string | Buffer
contentType: string
someMetaData: string
}
class FileRepository extends SimpleS3Repository<File> {
}
const s3Repository = new FileRepository<File>(new S3Client({ region: 'eu-central-1' }), 'my-bucket')
s3Repository.save({ key: 'foo/bar.json', content: '{}', contentType: 'application/json', someMetaData: 'super cool file' })
s3Repository.getOneAsString('foo/bar.json')
s3Repository.getOneMetadata('foo/bar.json')
s3Repository.deleteOne('foo/bar.json')
s3Repository.getSignedUploadUrl('foo/another-file.json')
s3Repository.getSignedDownloadUrl('foo/another-file.json')
s3Repository.list('foo')