README
@raydeck/ddb-manager - v3.6.1
Index
Classes
Functions
Functions
cappedPageMap
▸ cappedPageMap‹T, R›(paginator
: function, f
: function, limit
: number, lastKey?
: string, filter
: function): Promise‹[R[], string | undefined]›
Defined in src/index.ts:147
Iterate through pages until hitting a specified limit as generic. Allows pagination independent of DB limits
example
const [numbers, nextKey] = await cappedpageMap(
(l) => Number_page(account, l),
async (number) => number
);
Type parameters:
▪ T
Type of objects the paginator returns
▪ R
Type of return value (defaults to void)
Parameters:
▪ paginator: function
Function that returns a page as [object[], lastKey] tuple (like queryPage)
▸ (l?
: string): Promise‹[T[], string | undefined]›
Parameters:
Name | Type |
---|---|
l? |
string |
▪ f: function
Map function - takes output of queryPage and returns a value
▸ (arg
: T): Promise‹R›
Parameters:
Name | Type |
---|---|
arg |
T |
▪Default value
limit: number= 1000
Number of records beyond which we don't get more from DB.
▪Optional
lastKey: string
Last key used for the pagination (e.g. returned by the last call to cappedPageMap)
▪Default value
filter: function= async (arg) => true
async function for filtering results
▸ (arg
: T): Promise‹boolean›
Parameters:
Name | Type |
---|---|
arg |
T |
Returns: Promise‹[R[], string | undefined]›
pageMap
▸ pageMap‹T, R›(paginator
: function, f
: function, filter
: function): Promise‹R[]›
Defined in src/index.ts:122
Iterate through all pages of a function as generic
example
const numbers = await pageMap(
(l) => Number_page(account, l),
async (number) => number.getId()
);
Type parameters:
▪ T
Type of objects the paginator returns
▪ R
Type of return value (defaults to void)
Parameters:
▪ paginator: function
Function that returns a page as [object[], lastKey] tuple (like queryPage)
▸ (l?
: string): Promise‹[T[], string | undefined]›
Parameters:
Name | Type |
---|---|
l? |
string |
▪ f: function
Map function - takes output of queryPage and returns a value
▸ (arg
: T): Promise‹R›
Parameters:
Name | Type |
---|---|
arg |
T |
▪Default value
filter: function= async (arg) => true
async function for filtering results
▸ (arg
: T): Promise‹boolean›
Parameters:
Name | Type |
---|---|
arg |
T |
Returns: Promise‹R[]›
queryPage
▸ queryPage(__namedParameters
: object, lastKey?
: string): Promise‹[object[], string | undefined]›
Defined in src/index.ts:43
Run paginated query on dynamoDB table
Parameters:
▪ __namedParameters: object
Query options
Name | Type | Default |
---|---|---|
IndexName |
string | - |
Key |
string | - |
Limit |
number | 50 |
TableName |
string | - |
Value |
string | number | - |
isReversed |
boolean | false |
▪Optional
lastKey: string
Specifies where to start query. Undefined returned when no more items found
Returns: Promise‹[object[], string | undefined]›
scanPage
▸ scanPage(__namedParameters
: object, lastKey?
: string): Promise‹[object[], string | undefined]›
Defined in src/index.ts:87
Iterate through whole table - returns only the fields specified
Parameters:
▪ __namedParameters: object
Scan options
Name | Type |
---|---|
TableName |
string |
fields |
string[] |
▪Optional
lastKey: string
Returns: Promise‹[object[], string | undefined]›
setDDB
▸ setDDB(newDDB
: DocumentClient): void
Defined in src/index.ts:13
Set new instance of DynamoDB for ddb-manager to use
Parameters:
Name | Type | Description |
---|---|---|
newDDB |
DocumentClient | Instance of DynamoDB |
Returns: void
@raydeck/ddb-manager - v3.6.1 › DDBError
Class: DDBError
Class for high-level DDBManager errors that can include the original raw DDB/AWS error
Hierarchy
-
↳ DDBError
Index
Properties
Properties
message
• message: string
Inherited from DDBError.message
Defined in node_modules/typescript/lib/lib.es5.d.ts:974
name
• name: string
Defined in node_modules/typescript/lib/lib.es5.d.ts:973
rawError Optional
• rawError? : Error
Defined in src/index.ts:20
stack Optional
• stack? : string
Defined in node_modules/typescript/lib/lib.es5.d.ts:975
Error Static
▪ Error: ErrorConstructor
Defined in node_modules/typescript/lib/lib.es5.d.ts:984
@raydeck/ddb-manager - v3.6.1 › DDBHandler
Class: DDBHandler
Manager to handle CRUD operations on a dynamoDB item
Hierarchy
- DDBHandler
Index
Constructors
Properties
Methods
- _create
- _update
- cacheIncrements
- delete
- get
- has
- hashKey
- hashPage
- increment
- indexPage
- load
- loadFromItem
- processRemoves
- processUpdates
- remove
- set
- setId
- setValues
Constructors
constructor
+ new DDBHandler(tableName
: string, hashKey
: string): DDBHandler
Defined in src/index.ts:194
Parameters:
Name | Type | Default |
---|---|---|
tableName |
string | - |
hashKey |
string | "id" |
Returns: DDBHandler
Properties
_hashKey Protected
• _hashKey: string
Defined in src/index.ts:182
Item partition key name
cachedValues
• cachedValues: object
Defined in src/index.ts:178
Item attributes
Type declaration:
- [ key: string]: any
exists
• exists: boolean = false
Defined in src/index.ts:190
Flag that indicates whether item saved persistently. If true, item exists in dynamoDB table; if false, item does not exist in dynamoDB table
id
• id: object
Defined in src/index.ts:186
Item primary key
Type declaration:
loaded
• loaded: boolean = false
Defined in src/index.ts:194
Flag that indicates where item data comes from. If true, data was passed via loadFromItem; if false, data was loaded directly from dynamoDB table
tableName Protected
• tableName: string
Defined in src/index.ts:174
DynamoDB table item lives in
Methods
_create
▸ _create(o
: object, id
: any, options
: object): Promise‹this›
Defined in src/index.ts:497
Create new dynamoDB Item
If item with primary key already exists, that item will be replaced
Parameters:
Name | Type | Default | Description |
---|---|---|---|
o |
object | - | Shape of item |
id |
any | - | Items primary key |
options |
object | {} | Options for dynamoDB put operation |
Returns: Promise‹this›
_update Protected
▸ _update(updates
: object): Promise‹this›
Defined in src/index.ts:444
Update attributes
Parameters:
Name | Type | Description |
---|---|---|
updates |
object | Object of attribute key/value pairs |
Returns: Promise‹this›
cacheIncrements Protected
▸ cacheIncrements(increments
: object): [string, number][]
Defined in src/index.ts:280
Cache increments.
Updates are saved locally only. Item in dynamoDB table will not be updated by this function
Parameters:
Name | Type | Description |
---|---|---|
increments |
object | increments to item attributes (e.g. {count:5} would increment count by +5) |
Returns: [string, number][]
delete
▸ delete(key?
: string | object): Promise‹void›
Defined in src/index.ts:593
Delete item
Parameters:
Name | Type | Description |
---|---|---|
key? |
string | object | Primary key of item to delete |
Returns: Promise‹void›
get
▸ get‹T›(key
: string, def?
: T): T | undefined
Defined in src/index.ts:551
Get attribute
Type parameters:
▪ T
Parameters:
Name | Type | Description |
---|---|---|
key |
string | Name of attribute |
def? |
T | Default value for attribute |
Returns: T | undefined
has
▸ has(key
: string): boolean
Defined in src/index.ts:558
Check if attribute exists
Parameters:
Name | Type | Description |
---|---|---|
key |
string | Name of attribute |
Returns: boolean
hashKey
▸ hashKey(): string
Defined in src/index.ts:211
Return partition key name
Returns: string
hashPage
▸ hashPage(hashValue
: any, lastValue?
: string): Promise‹[object[], string]›
Defined in src/index.ts:606
Run paginated query against partition key
Parameters:
Name | Type | Description |
---|---|---|
hashValue |
any | Value of items partition key |
lastValue? |
string | Specifies where to start query. Undefined returned when no more items found |
Returns: Promise‹[object[], string]›
increment
▸ increment(field
: string, byValue
: number): Promise‹this›
Defined in src/index.ts:394
Increment one attribute
Parameters:
Name | Type |
---|---|
field |
string |
byValue |
number |
Returns: Promise‹this›
indexPage
▸ indexPage(indexName
: string, key
: string, value
: any, lastValue?
: string): Promise‹[object[], string]›
Defined in src/index.ts:623
Run paginated query against global or secondary index
Parameters:
Name | Type | Description |
---|---|---|
indexName |
string | Name of global or secondary index |
key |
string | Partition (or sort) key to search against |
value |
any | Value an items "Key" should have |
lastValue? |
string | - |
Returns: Promise‹[object[], string]›
load
▸ load(o
: any): Promise‹this›
Defined in src/index.ts:565
Initialize instance from dynamoDB item
Parameters:
Name | Type | Description |
---|---|---|
o |
any | Item primary key |
Returns: Promise‹this›
loadFromItem
▸ loadFromItem(Item
: object): this
Defined in src/index.ts:583
Initialize instance from a plain old javascript object
Parameters:
Name | Type | Description |
---|---|---|
Item |
object |
Returns: this
processRemoves Protected
▸ processRemoves(keys
: string[]): string[]
Defined in src/index.ts:318
Transform an removes object to an array of tuples.
Updates are saved locally only. Item in dynamoDB table will not be updated by this function
Parameters:
Name | Type |
---|---|
keys |
string[] |
Returns: string[]
processUpdates Protected
▸ processUpdates(updates
: object): [string, any][]
Defined in src/index.ts:244
Transform an updates object to an array of tuples.
Updates are saved locally only. Item in dynamoDB table will not be updated by this function
Parameters:
Name | Type | Description |
---|---|---|
updates |
object | Updates to item attributes |
Returns: [string, any][]
remove
▸ remove(key
: string): Promise‹void›
Defined in src/index.ts:226
Remove attribute from a record
Parameters:
Name | Type | Description |
---|---|---|
key |
string | Name of attribute |
Returns: Promise‹void›
set
▸ set(key
: string, value
: any): Promise‹void›
Defined in src/index.ts:219
Set attribute
Parameters:
Name | Type | Description |
---|---|---|
key |
string | Name of attribute |
value |
any | Value of attribute |
Returns: Promise‹void›
setId
▸ setId(id
: string | object): void
Defined in src/index.ts:205
Set id (primary key) of an item
Parameters:
Name | Type | Description |
---|---|---|
id |
string | object | Item primary key Id should be an object for a composite primary key |
Returns: void
setValues
▸ setValues(mapOfValues
: object): Promise‹void›
Defined in src/index.ts:233
Set multiple attributes
Parameters:
Name | Type | Description |
---|---|---|
mapOfValues |
object | Object of attribute key/value pairs (e.g. {attribute1: "value1", attribute2: false} ) |
Returns: Promise‹void›