Skip to content

Instantly share code, notes, and snippets.

@yustam
Created April 7, 2014 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yustam/10016546 to your computer and use it in GitHub Desktop.
Save yustam/10016546 to your computer and use it in GitHub Desktop.
delete items in Amazon SimpleDB (require node.js and aws-javascript-sdk)
var config = require('../config.json');
var AWS = require('aws-sdk');
AWS.config.loadFromPath('config.json');
var simpledb = new AWS.SimpleDB();
var delete_item = function (name, data) {
var params = {
DomainName: config.domainName,
Items: [
{
Name: name,
Attributes: data.Attributes
}
]
};
simpledb.batchDeleteAttributes(params, function (err, data) {
if (err) {
console.log(err);
} else {
console.log('delete: ' + name);
}
});
};
var get_delete_item = function (name) {
var params = {
DomainName: config.domainName,
ItemName: name
};
simpledb.getAttributes(params, function (err, data) {
if (err) {
console.log(err);
} else {
delete_item(name, data);
}
});
};
var search_delete_items = function (sql, next_token) {
var params = {
SelectExpression: sql,
NextToken: next_token
};
simpledb.select(params, function (err, data) {
if (err) {
console.log(err);
} else {
data.Items.forEach(function (item) {
get_delete_item(item.Name);
});
if (data.NextToken) {
search_items(sql, data.NextToken)
}
}
});
};
search_delete_items("select * from `" + config.domainName + "` where Level = 'INFO'", null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment