Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (80 sloc) 1.97 KB
import AWS from "aws-sdk";
const dynamoDB = new AWS.DynamoDB.DocumentClient();
interface UpdateItemParams {
TableName: string;
Key: {
[key: string]: string;
};
UpdateExpression: string;
ExpressionAttributeValues: {
[key: string]: string | number | undefined | null;
};
ReturnValues?: string;
}
interface GetItemParams {
TableName: string;
Key: {
[key: string]: string;
};
}
interface ScanItemsParams {
TableName: string;
FilterExpression?: string;
ExpressionAttributeNames?: {
[key: string]: string;
};
ExpressionAttributeValues?: {
[key: string]: string | number | undefined | null;
};
}
export const updateItem = async (
params: UpdateItemParams
): Promise<AWS.DynamoDB.DocumentClient.UpdateItemOutput> => {
const query = {
...params
};
return new Promise((resolve, reject) => {
dynamoDB.update(query, (err, result) => {
if (err) {
console.error(err);
reject(err);
} else {
resolve(result);
}
});
});
};
export const getItem = async (
params: GetItemParams
): Promise<AWS.DynamoDB.DocumentClient.GetItemOutput> => {
const query = {
...params
};
return new Promise((resolve, reject) => {
dynamoDB.get(query, (err, result) => {
if (err) {
console.error(err);
reject(err);
} else {
resolve(result);
}
});
});
};
export const scanItems = async (
params: ScanItemsParams
): Promise<AWS.DynamoDB.DocumentClient.ScanOutput> => {
const query = {
...params
};
return new Promise((resolve, reject) => {
dynamoDB.scan(query, (err, result) => {
if (err) {
console.error(err);
reject(err);
} else {
resolve(result);
}
});
});
};
You can’t perform that action at this time.