Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DefaultModel

Default Model

This basic model has some basic methods to interact with DynamoDB. It has implemented all the typical CRUD operations, and translates them into DynamoDB DocumentClient calls. By using a model, you can avoid having to learn how to work with DynamoDB.

If you want to add more methods to your model, you can create your own class extended from this one.

Hierarchy

Implements

Index

Constructors

constructor

Properties

documentClient

documentClient: DocumentClient

DynamoDBDocument client instance. Must be declared before configuring the model.

type

{DocumentClient}

memberof

Model

Optional hasTenantRegExp

hasTenantRegExp: RegExp

Regular expression to use when checking if the hash key has the tenant prefixed.

type

{RegExp}

memberof

Model

hash

hash: string

The name of the hash key.

type

{string}

memberof

Model

hashType

hashType: string = "string"

The type of the hash key.

type

{string}

memberof

Model

indexName

indexName: string = "byGSIK"

The name of the index to use when running an index operation. By default if will be called byGSIK. If the index is not created before hand, and the model is configured with a tenant, then the method will fail.

type

{string}

memberof

Model

maxGSIK

maxGSIK: number = 10

The maximum GSIK values to use to index the models. This is necessary when configuring a tenant, since you can't configure an IAM policy to restrict access to an item with a prefix on its hash ID. So, a GSIK will be configured on every item by the library, using the tenant value plus a number between 0 and maxGSIK. Then you can create an IAM policy that restrict access on the index (called by defaylt byGSIK) with access only on the items with the appropiate GSIK value.

type

{number}

memberof

Model

Optional range

range: string

The name of the range key.

type

{string}

memberof

Model

rangeType

rangeType: string = "string"

The type of the range key.

type

{string}

memberof

Model

struct

struct: any

Struct instance created from the struct data passed through the model configuration.

type

{*}

memberof

Model

table

table: string

The table name. If not provided it will try to use the table name globally configured.

type

{string}

memberof

Model

Optional tenant

tenant: string

The tenant unique identifier.

type

{string}

memberof

Model

track

track: boolean = false

Value used to track the dates where modifications were done to the item.

type

{boolean}

memberof

Model

Methods

addTenant

callback

  • callback(callback: function): void
  • Does the stored DynamoDB DocumentClient call and wraps the result in a callback. It handles error produced on the call, and passes the onto the callback on the err argument.

    Parameters

    • callback: function

      Callback function to invoke with the data or the error generated on the DynamoDB DocumentClient call.

        • (error: Error | null, data?: IItem | void): void
        • Parameters

          • error: Error | null
          • Optional data: IItem | void

          Returns void

    Returns void

create

delete

get

getKey

index

promise

  • promise(): Promise<IItem | void>

removeTenant

trackChanges

update

validate

  • validate(body: IItem): boolean

Generated using TypeDoc