Skip to content

Commit

Permalink
Add support for batch record deletion
Browse files Browse the repository at this point in the history
For example:

    const table = airtable.base('app123').table('My Table');
    await table.destroy(['rec123', 'rec456']);
  • Loading branch information
Evan Hahn committed Apr 23, 2019
1 parent 08df6b7 commit daa5e68
Show file tree
Hide file tree
Showing 5 changed files with 500 additions and 11 deletions.
2 changes: 2 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = function(grunt) {
setTimeout: true,
jest: true,
describe: true,
beforeAll: true,
afterAll: true,
it: true,
expect: true,
Promise: true,
Expand Down
23 changes: 20 additions & 3 deletions lib/table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var isArray = require('lodash/isArray');
var isPlainObject = require('lodash/isPlainObject');
var assign = require('lodash/assign');
var forEach = require('lodash/forEach');
Expand Down Expand Up @@ -109,9 +110,25 @@ var Table = Class.extend({
record.putUpdate(recordData, opts, done);
}
},
_destroyRecord: function(recordId, done) {
var record = new Record(this, recordId);
record.destroy(done);
_destroyRecord: function(recordIdsOrId, done) {
if (isArray(recordIdsOrId)) {
var that = this;
var queryParams = {records: recordIdsOrId};
this._base.runAction('delete', '/' + this._urlEncodedNameOrId(), queryParams, null, function (err, response, results) {
if (err) {
done(err);
return;
}

var records = map(results.records, function(recordJson) {
return new Record(that, recordJson.id, null);
});
done(null, records);
});
} else {
var record = new Record(this, recordIdsOrId);
record.destroy(done);
}
},
_listRecords: function(limit, offset, opts, done) {
var that = this;
Expand Down
Loading

0 comments on commit daa5e68

Please sign in to comment.