mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
Much better typed DynamoDB.DocumentClient. (#9500)
This commit is contained in:
committed by
Masahiro Wakame
parent
d29b1fc285
commit
21286f4d20
@@ -253,4 +253,107 @@ sqs.setQueueAttributes({
|
||||
else console.log(data); // successful response
|
||||
});
|
||||
|
||||
|
||||
|
||||
var dynamoDBDocClient:AWS.DynamoDB.DocumentClient;
|
||||
dynamoDBDocClient = new AWS.DynamoDB.DocumentClient();
|
||||
dynamoDBDocClient = new AWS.DynamoDB.DocumentClient({});
|
||||
dynamoDBDocClient.createSet([1, 2, 3], { validate: true });
|
||||
dynamoDBDocClient.get(
|
||||
{
|
||||
TableName: 'TABLE_NAME',
|
||||
Key: { userId: 'abc123', email: 'abc123@abc123.com' }
|
||||
},
|
||||
function(err, data) {
|
||||
if (err) console.log(err, err.stack); // an error occurred
|
||||
else console.log(data); // successful response
|
||||
}
|
||||
);
|
||||
dynamoDBDocClient.put(
|
||||
{
|
||||
TableName: 'TABLE_NAME',
|
||||
Item: {
|
||||
userId: 'abc123',
|
||||
email: 'abc123@abc123.com',
|
||||
firstName: 'Matt',
|
||||
lastName: 'Forrester the ' + new Date().getTime()
|
||||
}
|
||||
},
|
||||
function(err, data) {
|
||||
if (err) console.log(err, err.stack); // an error occurred
|
||||
else console.log(data); // successful response
|
||||
}
|
||||
);
|
||||
dynamoDBDocClient.delete(
|
||||
{
|
||||
TableName: 'TABLE_NAME',
|
||||
Key: {
|
||||
userId: 'abc123',
|
||||
email: 'abc123@abc123.com'
|
||||
}
|
||||
},
|
||||
function(err, data) {
|
||||
if (err) console.log(err, err.stack); // an error occurred
|
||||
else console.log(data); // successful response
|
||||
}
|
||||
);
|
||||
dynamoDBDocClient.update(
|
||||
{
|
||||
TableName: 'TABLE_NAME',
|
||||
Key: {
|
||||
userId: 'abc123',
|
||||
email: 'abc123@abc123.com'
|
||||
},
|
||||
AttributeUpdates: {
|
||||
thingsWithWheels: {
|
||||
Action: 'PUT',
|
||||
Value: dynamoDBDocClient.createSet(
|
||||
[
|
||||
'SkateBoard',
|
||||
'Skates',
|
||||
'Mountain Bike',
|
||||
'Evolve Electric Skateboard'
|
||||
],
|
||||
{ validate: true }
|
||||
)
|
||||
},
|
||||
age: {
|
||||
Action: 'PUT',
|
||||
Value: 35
|
||||
}
|
||||
}
|
||||
},
|
||||
function(err, data) {
|
||||
if (err) console.log(err, err.stack); // an error occurred
|
||||
else console.log(data); // successful response
|
||||
}
|
||||
);
|
||||
dynamoDBDocClient.scan(
|
||||
{
|
||||
TableName: 'TABLE_NAME',
|
||||
KeyConditions: {
|
||||
age: {
|
||||
ComparisonOperator: 'EQ',
|
||||
AttributeValueList: [35]
|
||||
}
|
||||
}
|
||||
},
|
||||
function(err, data) {
|
||||
if (err) console.log(err, err.stack); // an error occurred
|
||||
else console.log(data); // successful response
|
||||
}
|
||||
);
|
||||
dynamoDBDocClient.query(
|
||||
{
|
||||
TableName: 'TABLE_NAME',
|
||||
KeyConditions: {
|
||||
userId: {
|
||||
ComparisonOperator: 'EQ',
|
||||
AttributeValueList: ['abc123']
|
||||
}
|
||||
}
|
||||
},
|
||||
function(err, data) {
|
||||
if (err) console.log(err, err.stack); // an error occurred
|
||||
else console.log(data); // successful response
|
||||
}
|
||||
);
|
||||
|
||||
94
aws-sdk/aws-sdk.d.ts
vendored
94
aws-sdk/aws-sdk.d.ts
vendored
@@ -166,12 +166,106 @@ declare module "aws-sdk" {
|
||||
constructor(options?: any);
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
|
||||
export module DynamoDB {
|
||||
|
||||
interface _DDBDC_Generic {
|
||||
TableName: string;
|
||||
ExpressionAttributeNames?: string[];
|
||||
ReturnConsumedCapacity?: "INDEXES" | "TOTAL" | "NONE";
|
||||
}
|
||||
|
||||
type _DDBDC_ComparisonOperator = "EQ" | "NE" | "IN" | "LE" | "LT" | "GE" | "GT" | "BETWEEN" | "NOT_NULL" | "NULL" | "CONTAINS" | "NOT_CONTAINS" | "BEGINS_WITH"
|
||||
type _DDBDC_Keys = { [someKey: string]: any };
|
||||
type _DDBDC_KeyComparison = {
|
||||
[someKey: string]: {
|
||||
AttributeValueList: any[];
|
||||
ComparisonOperator: _DDBDC_ComparisonOperator;
|
||||
}
|
||||
};
|
||||
|
||||
interface _DDBDC_Reader extends _DDBDC_Generic {
|
||||
ConsistentRead?: boolean;
|
||||
ProjectionExpression?: string;
|
||||
AttributesToGet?: string[];
|
||||
}
|
||||
|
||||
interface _DDBDC_Writer extends _DDBDC_Generic {
|
||||
ExpressionAttributeValues?: _DDBDC_Keys;
|
||||
ReturnItemCollectionMetrics?: "SIZE" | "NONE";
|
||||
ReturnValues?: "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW";
|
||||
ConditionExpression?: string;
|
||||
ConditionalOperator?: "AND" | "OR";
|
||||
Expected?: {
|
||||
[someKey: string]: {
|
||||
AttributeValueList: any[];
|
||||
ComparisonOperator: _DDBDC_ComparisonOperator;
|
||||
Exists: boolean;
|
||||
Value: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface UpdateParam extends _DDBDC_Writer {
|
||||
Key: _DDBDC_Keys;
|
||||
AttributeUpdates: {
|
||||
[someKey: string]: {
|
||||
Action: "PUT" | "ADD" | "DELETE";
|
||||
Value: any
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface QueryParam extends _DDBDC_Reader {
|
||||
ConditionalOperator?: "AND" | "OR";
|
||||
ExclusiveStartKey?: _DDBDC_Keys;
|
||||
ExpressionAttributeValues?: _DDBDC_Keys;
|
||||
FilterExpression?: string;
|
||||
IndexName?: string;
|
||||
KeyConditionExpression?: string;
|
||||
KeyConditions?: _DDBDC_KeyComparison;
|
||||
Limit?: number;
|
||||
QueryFilter?: _DDBDC_KeyComparison;
|
||||
ScanIndexForward?: boolean;
|
||||
Select?: "ALL_ATTRIBUTES" | "ALL_PROJECTED_ATTRIBUTES" | "SPECIFIC_ATTRIBUTES" | "COUNT";
|
||||
}
|
||||
|
||||
interface ScanParam extends QueryParam {
|
||||
Segment?: number;
|
||||
ScanFilter?: _DDBDC_KeyComparison;
|
||||
TotalSegments?: number;
|
||||
}
|
||||
|
||||
interface GetParam extends _DDBDC_Reader {
|
||||
Key: _DDBDC_Keys;
|
||||
}
|
||||
|
||||
interface PutParam extends _DDBDC_Writer {
|
||||
Item: _DDBDC_Keys;
|
||||
}
|
||||
|
||||
interface DeleteParam extends _DDBDC_Writer {
|
||||
Key: _DDBDC_Keys;
|
||||
}
|
||||
|
||||
export class DocumentClient {
|
||||
constructor(options?: any);
|
||||
get(params: GetParam, next: (err: any, data: any) => void): void;
|
||||
put(params: PutParam, next: (err: any, data: any) => void): void;
|
||||
delete(params: DeleteParam, next: (err: any, data: any) => void): void;
|
||||
query(params: QueryParam, next: (err: any, data: any) => void): void;
|
||||
scan(params: ScanParam, next: (err: any, data: any) => void): void;
|
||||
update(params: UpdateParam, next: (err: any, data: any) => void): void;
|
||||
createSet(list: any[], options?: { validate?: boolean }): { values: any[], type: string };
|
||||
batchGet(params: any, next: (err: any, data: any) => void): void;
|
||||
batchWrite(params: any, next: (err: any, data: any) => void): void;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
|
||||
export module SQS {
|
||||
|
||||
export interface SqsOptions {
|
||||
|
||||
Reference in New Issue
Block a user