Skip to content

Commit

Permalink
Merge pull request sequelize#2988 from ThankYouMotion/mssqlUUID
Browse files Browse the repository at this point in the history
UUID datatype mapping for mssql
  • Loading branch information
mickhansen committed Jan 27, 2015
2 parents 2cb214b + 8125028 commit 3ccca4a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/dialects/mssql/data-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var DataTypes = require('../../data-types');
//drop table Group
DataTypes.BOOLEAN = 'BIT';
DataTypes.NOW = 'GETDATE()';
DataTypes.UUID = 'UNIQUEIDENTIFIER';
DataTypes.UUID = 'CHAR(36)';
DataTypes.BLOB = 'VARBINARY(MAX)';
DataTypes.STRING._typeName = 'NVARCHAR';

Expand Down
4 changes: 4 additions & 0 deletions lib/dialects/mssql/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ module.exports = (function() {
dataType = dataType.replace(/BLOB/, 'VARBINARY(MAX)');
}

if (Utils._.includes(dataType, 'UUID')) {
dataType = dataType.replace(/UUID/, DataTypes.UUID);
}

return dataType;
}

Expand Down
3 changes: 2 additions & 1 deletion test/integration/associations/belongs-to-many.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
var Beacons = this.sequelize.define('Beacon', {
id: {
primaryKey: true,
type: DataTypes.UUID
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
name: {
type: DataTypes.STRING
Expand Down
3 changes: 2 additions & 1 deletion test/integration/associations/has-many.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,8 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
var Beacons = this.sequelize.define('Beacon', {
id: {
primaryKey: true,
type: DataTypes.UUID
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
name: {
type: DataTypes.STRING
Expand Down
5 changes: 0 additions & 5 deletions test/integration/instance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1754,11 +1754,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
var query = { where: { username: 'fnord' }};

self.User.find(query).success(function(user2) {
if (dialect === 'mssql') {
user1.dataValues.uuidv1 = user1.dataValues.uuidv1.toUpperCase();
user1.dataValues.uuidv4 = user1.dataValues.uuidv4.toUpperCase();
}

expect(user1.equals(user2)).to.be.true;
done();
});
Expand Down

0 comments on commit 3ccca4a

Please sign in to comment.