# @repit/lambda-query

> Simple & Opinionated DynamoDB Query API for AWS Lambda.

Latest version **1.0.0** (published 2017-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @repit/lambda-query
pnpm add @repit/lambda-query
yarn add @repit/lambda-query
bun add @repit/lambda-query
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-12-16 |
| First published | 2017-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ion Suman |
| Maintainers | sumanion |

## Links

- npm: https://www.npmjs.com/package/@repit/lambda-query
- npm.io page: https://npm.io/package/@repit/lambda-query

## Recent versions

- 1.0.0 (latest) — 2017-12-16

## README

# Lambda Query

Simple & Opinionated DynamoDB Query API for AWS Lambda.

## Installation

```bash
$ npm install @repit/lambda-query --save
```

## Usage

```js
'use strict'

// Load the Query class.
const Query = require('@repit/lambda-query')

// Create a new Query object.
const query = new Query()

// Configure AWS DynamoDB.
// Note: This is not required if you add proper IAM roles.
query.configure({
  region: '',
  accessKeyId: '',
  secretAccessKey: ''
})

// Change default table name.
// Note: Default table name is `Store`.
query.tableName('')

// Get current instance of `DocumentClient`.
query.client()

// Read a single item from DynamoDB which match: { Type: 'Error', Name: 'InvalidUser' },
// and include all attributes.
query.resolve('Error:InvalidUser:*') // Promise

// Read a single item from DynamoDB which match: { Type: 'Error', Name: 'InvalidUser' },
// and include only `en,fr,de` attributes.
query.resolve('Error:InvalidUser:en,fr,de') // Promise

// Read many items from DynamoDB which match: { Type: 'Error' },
// and include all attributes.
query.resolve('Error:*:*') // Promise

// Read many items from DynamoDB which match: { Type: 'Error' },
// and include only `en,fr,de` attributes.
query.resolve('Error:*:en,fr,de') // Promise

// Read many items from DynamoDB which match:
// { Type: 'Error', Name: 'InvalidUser' } and { Type: 'Error', Name: 'InvalidEmail' },
// and include only `en,fr,de` attributes.
query.resolve([
  'Error:InvalidUser:en',
  'Error:InvalidEmail:fr,de'
]) // Promise
```

## Caching

This package requires [@repit/lambda-cache](https://www.npmjs.com/package/@repit/lambda-cache) to cache queries.

**Usage is pretty simple:**

```js
'use strict'

const Query = require('@repit/lambda-query')
const Cache = require('@repit/lambda-cache')

const cache = new Cache()

exports.handler = (event, context, callback) => {
  const query = new Query(cache)
}
```

> To learn how to invalidate cache visit:
  [@repit/lambda-cache](https://www.npmjs.com/package/@repit/lambda-cache)

## Table Structure

Default table name is `Store`, which can be changed with `query.tableName(name)`.

Primary key requirements:

- **Partition Key** should be `Type (String)`;
- **Sort Key** should be `Name (String)`;

## License

MIT

---
_Source: https://npm.io/package/@repit/lambda-query · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
