GitHub

Operations

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 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 ReadDatabase {
    partKey: string
    sortKey: string
    memory?: boolean
}
interface QueryDatabase {
    partKey: string
    beginsWith?: string
    greaterOrEqual?: string
    lessOrEqual?: string
    reverse?: boolean
    nextToken?: string
    limit?: number
}
interface RemoveFromDatabase {
    partKey: string
    sortKey: string
}


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


async function writeToDatabase(input: WriteToDatabase): Promise<OperationResponse | undefined> {
    // ...
}
async function readDatabase(input: ReadDatabase): Promise<OperationResponse | undefined> {
    // ...
}
async function queryDatabase(input: QueryDatabase): Promise<OperationResponse | undefined> {
    // ...
}
async function removeFromDatabase(input: RemoveFromDatabase): 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' } })
    .readDatabase({ partKey: 'my-part', sortKey: 'my-sort', memory: true })
    .queryDatabase({ partKey: 'my-part', beginsWith: 'my', limit: 10 })
    .removeFromDatabase({ partKey: 'my-part', sortKey: 'my-sort' })
    .send()

API Reference

Write To Database Input

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

Read Database Input

ParameterTypeRequiredDescription
partKeystringtruePartition key of the record
sortKeystringtrueSort key of the record
memorystringfalseFlag 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

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
Previous
Lookup Keys