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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-13 10:24:20 +00:00
|
|
|
|
|
|
|
|
export function updateItem(client, updateCondition: object): Promise<object> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.update(updateCondition, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function describeTable(client, table: string): Promise<object> {
|
|
|
|
|
const params = {
|
|
|
|
|
TableName: table,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.describeTable(params, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createTable(client, tableParameters: object) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.createTable(tableParameters, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function putItem(client, newItemDetails: object): Promise<object> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
client.put(newItemDetails, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
} else {
|
|
|
|
|
resolve(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|