Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ NAN_METHOD(Connection::PutCopyData) {

Connection* self = NODE_THIS();

if (!node::Buffer::HasInstance(info[0])) {
return Nan::ThrowTypeError("First argument must be a Buffer");
}

v8::Local<v8::Object> buffer = info[0].As<v8::Object>();

char* data = node::Buffer::Data(buffer);
Expand Down
10 changes: 9 additions & 1 deletion test/copy-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var bufferFrom = require('buffer-from')
describe('COPY IN', function() {
helper.setupIntegration();

it('check existing data assuptions', function() {
it('check existing data assumptions', function() {
this.pq.exec('SELECT COUNT(*) FROM test_data');
assert.equal(this.pq.getvalue(0, 0), 3);
});
Expand Down Expand Up @@ -45,4 +45,12 @@ describe('COPY IN', function() {
this.pq.exec('SELECT COUNT(*) FROM test_data');
assert.equal(this.pq.getvalue(0, 0), 4);
});

it('throws TypeError when non-Buffer is passed to putCopyData', function() {
assert.throws(function() {
this.pq.$putCopyData("not a buffer");
}.bind(this), function(err) {
return err instanceof TypeError;
});
});
});