Skip to main content
Version: v2

Database

Serves as a single entry point for a collection of Tables, Entities, and AccessPatterns via the Registry Table Action:

import { Database } from 'dynamodb-toolbox/database'

// Build `Registry` first
const PokeRegistry = PokeTable.build(Registry)
.registerEntities(TrainerEntity, PokemonEntity)
.registerAccessPatterns({ trainers, trainerPokemons })

const PokeDB = new Database({
pokedex: PokeRegistry
})

// Get a Registry by key
PokeDB.tables.pokedex

// Get an Entity by `entityName`
PokeDB.tables.pokedex.entities.trainer

// Get an AccessPattern by key
PokeDB.tables.pokedex.accessPatterns.trainers.query(...)

// Or use the `.query` shorthand
PokeDB.tables.pokedex.query.trainers(...)
info

Because Database can reduce the effectiveness of tree-shaking, we recommend using it only:

Constructor​

The Database constructor takes two parameters: tables and optional options.

tables​

(required)

The Tables contained in the Database. Each can be either a Table or a Registry:

const tables = {
pokedex: PokeRegistry
other: OtherRegistry
}

const PokeDB = new Database(tables)

options​

Additional options (optional):

meta​

Attaches metadata to the Database (as an object property).

The meta object can include a title and description, both of which must be strings. Additional fields can be of any type:

const PokeDB = new Database(
...,
{
meta: {
title: 'Pokedex',
description:
'An Awesome Database for development use',
other: { field: 'of any type' }
}
}
)

// πŸ‘‡ Directly access/modify metadata
console.log(PokeDB.meta)
PokeDB.meta.foo = 'A new field'

Building Database Actions​

To allow for extensibility, better code-splitting and lighter bundles, Database only expose a .build(...) method which acts as a gateway to perform Database Actions:

import { MCPToolkit } from 'dynamodb-toolbox/database/actions/mcpToolkit'

const mcpToolkit = PokeDB.build(MCPToolkit)