diff --git a/lib/mysql.js b/lib/mysql.js index 52292dc..1b56900 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -367,6 +367,9 @@ MySQL.prototype.toColumnValue = function(prop, val) { params: [val.lat, val.lng], }); } + if (prop.type === Buffer) { + return val; + } if (prop.type === Object) { return this._serializeObject(val); } diff --git a/test/datatypes.test.js b/test/datatypes.test.js index 3fff9ad..63d40c3 100644 --- a/test/datatypes.test.js +++ b/test/datatypes.test.js @@ -7,7 +7,7 @@ require('./init.js'); var assert = require('assert'); -var db, EnumModel, ANIMAL_ENUM; +var db, BlobModel, EnumModel, ANIMAL_ENUM; var mysqlVersion; describe('MySQL specific datatypes', function() { @@ -72,7 +72,20 @@ describe('MySQL specific datatypes', function() { }); }); }); - + it('should create a model instance with binary types', function(done) { + var str = 'This is a test'; + var name = 'bob'; + var bob = {name: name, bin: new Buffer.from(str)}; + BlobModel.create(bob, function(err, obj) { + assert.ok(!err); + assert.equal(obj.bin.toString(), str); + BlobModel.findOne({where: {name: name}}, function(err, found) { + assert.ok(!err); + assert.equal(found.bin.toString(), str); + done(); + }); + }); + }); it('should disconnect when done', function(done) { db.disconnect(); done(); @@ -93,7 +106,10 @@ function setup(done) { note: Object, extras: 'JSON', }); - + BlobModel = db.define('BlobModel', { + bin: {type: Buffer, dataType: 'blob', null: false}, + name: {type: String}, + }); query('SELECT VERSION()', function(err, res) { mysqlVersion = res && res[0] && res[0]['VERSION()']; blankDatabase(db, done);