Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

dynamodb-onetable

> 数据库
Open source

DynamoDB access and management for one table designs with NodeJS

716 stars0 likes0 views
WebsiteGitHub

About

DynamoDB access and management for one table designs with NodeJS

One Table to Rule Them All

The Easiest Way to Create DynamoDB Single Table Designs.

OneTable is the most evolved API for DynamoDB. It provides a dry, high-level, elegant syntax while enabling full access to the DynamoDB API.

OneTable works with JavaScript and TypeScript. For TypeScript, OneTable will create fully typed entities from your data schemas automatically.

Full Documentation

  • OneTable Documentation

OneTable Features

  • Schema supported one-table access to DynamoDB APIs.
  • Efficient storage and access of multiple entities in a single DynamoDB table.
  • High level API with type marshaling, validations, and extended query capability for get/delete/update operations.
  • Bidirectional conversion of DynamoDB types to Javascript types.
  • Generation of Conditional, Filter, Key and Update expressions.
  • Schema item definitions for attribute types, default values, enums, unique attributes and validations.
  • Option to invoke DynamoDB or simply generate API parameters.
  • Powerful field level validations with "required" and "unique" attributes.
  • Easy parameterization of filter and conditional queries.
  • Detailed metrics for Table, Tenant, Source, Index, Model and Operation.
  • Multi-page response aggregation.
  • Compound and templated key management.
  • Attribute mapping and packing.
  • Support for sparse GSIs that project keys and overloaded attributes.
  • Encrypted fields.
  • CreateTable, DeleteTable table and index admin operations.
  • Support for Batch, Transactions, GSI, LSI indexes.
  • Intercept hooks to modify DynamoDB requests and responses.
  • Controllable logging to see exact parameter, data and responses.
  • Simple and easy to read source.
  • Integrated statistics.
  • Safety options to prevent "rm -fr *".
  • TypeScript type inference from schema for full type validation on APIs, parameters, returns, and entities and attributes.
  • Migrations support via OneTable Migrate and OneTable CLI.
  • Graphical monitoring of single-table performance via SenseDeep.

Installation

bash
npm i dynamodb-onetable

Quick Tour

Import the OneTable library. If you are not using ES modules or TypeScript, use require to import the libraries.

javascript
import {Table} from 'dynamodb-onetable'

Import the DynamoDBClient class and create a DynamoDBClient instance.

javascript
import {DynamoDBClient} from '@aws-sdk/client-dynamodb'
const client = new DynamoDBClient({
    endpoint: `http://localhost:${PORT}`,
    region: 'local',
    credentials: new AWS.Credentials({
        accessKeyId: 'test',
        secretAccessKey: 'test',
    }),
})

If you are using the legacy AWS SDK V2, import the AWS DynamoDB class and create a DocumentClient instance.

javascript
import DynamoDB from 'aws-sdk/clients/dynamodb'
const client = new DynamoDB.DocumentClient(params)

Note: you can use the Table.setClient API to defer setting the client or replace the client at any time.

Initialize your OneTable Table instance and define your models via a schema.

javascript
const table = new Table({
    client: client,
    name: 'MyTable',
    schema: MySchema,
})

This will initialize your OneTable Table instance and define your models via a schema.

Schemas

Schemas define how items will be stored in your database and look like this:

…

To create an item:

javascript
let account = await Account.create({
    id: '8e7bbe6a-4afc-4117-9218-67081afc935b',
    name: 'Acme Airplanes',
})

This will write the following to DynamoDB:

javascript
{
    pk:         'account:8e7bbe6a-4afc-4117-9218-67081afc935b',
    sk:         'account:98034',
    id:         '8e7bbe6a-4afc-4117-9218-67081afc935b',
    name:       'Acme Airplanes',
    status:     'active',
    zip:        '98034',
    created:    1610347305510,
    updated:    1610347305510,
}

Get an item:

javascript
let account = await Account.get({
    id: '8e7bbe6a-4afc-4117-9218-67081afc935b',
})

which will return:

javascript
{
    id:       '8e7bbe6a-4afc-4117-9218-67081afc935b',
    name:     'Acme Airplanes',
    status:   'active',
    zip:      '98034',
}

To use a secondary index:

javascript
let user = await User.get({email: '[email protected]'}, {index: 'gs1'})

To find a set of items:

javascript
let users = await User.find({accountId: account.id})

let adminUsers = await User.find({accountId: account.id, role: 'admin'})

let users = await User.find(
    {accountId: account.id},
    {
        where: '${balance} > {100.00}',
    }
)

//  Get a count of matching users without returning the actual items
let users = await User.find({accountId: account.id, role: 'admin'}, {count: true})
let count = users.count

To update an item:

javascript
await User.update({id: userId, balance: 50})
await User.update({id: userId}, {add: {balance: 10.0}})
await User.update({id: userId}, {set: {status: '{active}'}})

To do a transactional update:

javascript
let transaction = {}
await Account.update({id: account.id, status: 'active'}, {transaction})
await User.update({id: user.id, role: 'user'}, {transaction})
await table.transact('write', transaction)

TypeScript

OneTable provides TypeScript type declaration files so that OneTable APIs, requests and responses can be fully type checked.

OneTable also creates type declarations for your table entities and attributes. TypeScript will catch any invalid entity or entity attribute references.

Using the magic of TypeScript dynamic typing, OneTable automatically converts your OneTable schema into fully typed generic Model APIs.

For example:

…

DynamoDB Articles

Here is a collection of articles that can help you on your way with DynamoDB and OneTable.

DynamoDB Topic Link
Intro to DynamoDB https://www.sensedeep.com/blog/posts/2021/dynamodb-onetable-tour.html
Data Modeling for DynamoDB https://www.sensedeep.com/blog/posts/2021/dynamodb-singletable-design.html
The What and Why of Single Table Design https://www.alexdebrie.com/posts/dynamodb-single-table/
DynamoDB with OneTable Schemas https://www.sensedeep.com/blog/posts/2021/dynamodb-schemas.html
DynamoDB OneTable API Overview https://www.sensedeep.com/blog/posts/2021/dynamodb-onetable-tour.html
DynamoDB Checklist https://www.sensedeep.com/blog/posts/2021/dynamodb-checklist.html
DynamoDB with TypeScript https://www.sensedeep.com/blog/posts/2021/dynamodb-typescript.html
DynamoDB Sparse GSIs https://www.sensedeep.com/blog/posts/2021/sparse-gsi-indexes.html
DynamoDB Attribute Packing https://www.sensedeep.com/blog/posts/2021/attribute-packing.html
Evolving DynamoDB Designs https://www.sensedeep.com/blog/posts/2021/evolving-dynamodb-designs.html
SenseDeep Migration Manager https://www.sensedeep.com/blog/posts/series/dynamodb-studio/migration-manager.html
SenseDeep DynamoDB Studio https://www.sensedeep.com/blog/posts/stories/dynamodb-studio.html
SenseDeep DynamoDB Quick Tour https://www.sensedeep.com/blog/posts/product/dynamodb-tour.html

Serverless Articles

And a few serverless articles:

Serverless Topic Link
How to Debug Serverless Apps https://www.sensedeep.com/blog/posts/stories/how-to-debug-serverless-apps.html
How to invoke HTTP without Waiting from Lambda https://www.sensedeep.com/blog/posts/stories/lambda-fast-http.html
Fast Logging with Lambda https://www.sensedeep.com/blog/posts/senselogs/serverless-logging.html

SenseDeep

Please try our SenseDeep Serverless Developer Studio that includes a full DynamoDB suite with single-table aware data browser, single-table designer, migration manager, provisioning planner and metrics.

.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptawsdynamodbnosqlorm

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库