2021-07-16 13:06:19 +00:00
|
|
|
export function listTables(client): Promise<object> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.listTables(function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data['TableNames']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 13:48:28 +00:00
|
|
|
export function getItem(client, table: string, key: object): Promise<object> {
|
2021-07-16 13:06:19 +00:00
|
|
|
const params = {
|
|
|
|
|
TableName: table,
|
2021-09-21 13:48:28 +00:00
|
|
|
Key: key,
|
2021-07-16 13:06:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.get(params, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
2021-09-21 13:48:28 +00:00
|
|
|
resolve(data['Item'] || {});
|
2021-07-16 13:06:19 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 13:48:28 +00:00
|
|
|
export function deleteItem(client, table: string, key: object): Promise<object> {
|
2021-07-16 13:06:19 +00:00
|
|
|
const params = {
|
|
|
|
|
TableName: table,
|
2021-09-21 13:48:28 +00:00
|
|
|
Key: key,
|
2021-07-16 13:06:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.delete(params, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 13:48:28 +00:00
|
|
|
export function queryTable(client, queryCondition: object): Promise<object> {
|
2021-07-16 13:06:19 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.query(queryCondition, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 13:48:28 +00:00
|
|
|
export function scanTable(client, scanCondition: object): Promise<object> {
|
2021-07-16 13:06:19 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.scan(scanCondition, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|