GitHub

RDK

Database

Database is a built-in NoSQL data storage with in-memory acceleration layer that you can interact via RDK.

  • You cannot write more than 25 records in parallel.
  • You cannot increase paths in parallel.
  • You cannot get more than 100 records in parallel.
  • You cannot remove more than 25 records in parallel.
  • You cannot run more than 10 queries in parallel.
interface WriteToDatabase {
    partKey: string
    sortKey: string
    memory?: boolean
    data: Record<string, any>
}


interface IncrementDatabase {
    partKey: string
    sortKey: string
    path?: string
    value: number
    memory?: boolean
    expireAt?: number,
}


interface ReadDatabase {
    partKey: string
    sortKey: string
    memory?: boolean
}


interface QueryDatabase {
    partKey: string
    beginsWith?: string
    greaterOrEqual?: string
    lessOrEqual?: string
    reverse?: boolean
    nextToken?: string
    limit?: number
}


interface RemovePartitionFromDatabase {
    partKey: string
}


interface RemoveFromDatabase extends RemovePartitionFromDatabase {
    sortKey: string
}


interface OperationResponse {
    success: boolean
    data?: any
    error?: string
}


export interface ReadDatabaseResponse extends OperationResponse {
    data?: { part: string, sort: string, data?: any }
}


export type DatabaseOutput = { partKey: string, sortKey: string, data?: any }
export interface QueryDatabaseResponse extends OperationResponse {
    data?: { items?: DatabaseOutput[], nextToken?: string }
}


async function writeToDatabase(input: WriteToDatabase): Promise<OperationResponse | undefined> {
    // ...
}
async function incrementDatabase(input: IncrementDatabase): Promise<OperationResponse | undefined> {
    // ...
}
async function readDatabase(input: ReadDatabase): Promise<ReadDatabaseResponse | undefined> {
    // ...
}
async function queryDatabase(input: QueryDatabase): Promise<QueryDatabaseResponse | undefined> {
    // ...
}
async function removeFromDatabase(input: RemoveFromDatabase): Promise<OperationResponse | undefined> {
    // ...
}
async function removePartitionFromDatabase(input: RemovePartitionFromDatabase): Promise<OperationResponse | undefined> {
    // ...
}

Usage

import RDK from '@retter/rdk'


const rdk = new RDK()


await rdk.writeToDatabase({ partKey: 'my-part', sortKey: 'my-sort', memory: true, data: { key: 'value' } })
await rdk.readDatabase({ partKey: 'my-part', sortKey: 'my-sort', memory: true })
await rdk.queryDatabase({ partKey: 'my-part', beginsWith: 'my', limit: 10 })
await rdk.removeFromDatabase({ partKey: 'my-part', sortKey: 'my-sort' })


await rdk.pipeline()
    .writeToDatabase({ partKey: 'my-part', sortKey: 'my-sort', memory: true, data: { key: 'value' } })
    .writeToDatabase({ partKey: 'my-part', sortKey: 'my-other-sort', memory: true, data: { key: 'value2' } })
    .readDatabase({ partKey: 'my-part', sortKey: 'my-sort', memory: true })
    .queryDatabase({ partKey: 'my-part', beginsWith: 'my', limit: 10 })
    .removeFromDatabase({ partKey: 'my-part', sortKey: 'my-sort' })
    .removePartitionFromDatabase({ partKey: 'my-part' })
    .send()

API Reference

Write To Database Input

ParameterTypeRequiredDescription
partKeystringtruePartition key of the record
sortKeystringtrueSort key of the record
memorybooleanfalseFlag to decide whether to put the data into memory or not
expireAtnumberfalseTime to live in seconds
dataRecord<string, any>trueActual data of the record

Increment Database Input

ParameterTypeRequiredDescription
partKeystringtruePartition key of the record
sortKeystringtrueSort key of the record
pathstringfalsePath to increase the value. If you don't provide it, data will end up as a number
memorybooleanfalseFlag to decide whether to put the data into memory or not
valuenumbertrueAmount

Read Database Input

ParameterTypeRequiredDescription
partKeystringtruePartition key of the record
sortKeystringtrueSort key of the record
memorybooleanfalseFlag to decide whether to put the data into memory or not

Remove From Database Input

ParameterTypeRequiredDescription
partKeystringtruePartition key of the record
sortKeystringtrueSort key of the record

Remove Partition From Database Input

ParameterTypeRequiredDescription
partKeystringtruePartition key of the record

Query Database Input

ParameterTypeRequiredDescription
partKeystringtruePartition key of the record
beginsWithstringfalseComparison filter for sort key
greaterOrEqualstringfalseComparison filter for sort key
lessOrEqualstringfalseComparison filter for sort key
reversebooleanfalseFlag to decide whether to scan data backwards or not
nextTokenstringfalsePagination token
limitnumberfalseLimits the number of records in the result

Operation Output

ParameterTypeRequiredDescription
successbooleantrueReturns true if operation is successful
dataanyfalseSuccessful response
errorstringfalseReason of failure

Read Database Response

ParameterTypeRequiredDescription
successbooleantrueReturns true if operation is successful
data{ part: string, sort: string, data?: any }falseSuccessful response
errorstringfalseReason of failure

Remove Partition From Database Response

ParameterTypeRequiredDescription
successbooleantrueReturns true if operation is successful
data{ executionId: string }falseSuccessful response
errorstringfalseReason of failure

Query Database Response

ParameterTypeRequiredDescription
successbooleantrueReturns true if operation is successful
data{ items?: DatabaseOutput[], nextToken?: string }falseSuccessful response
errorstringfalseReason of failure
Previous
Method Call