不要怂,就是干,撸起袖子干!

Commit b52f6295 by Mick Hansen

add databaseVersion() method for getting the dialect database version

1 parent 5aef119f
......@@ -50,6 +50,10 @@ module.exports = (function() {
throwMethodUndefined('createTableQuery');
},
versionQuery: function(tableName, attributes, options) {
throwMethodUndefined('versionQuery');
},
describeTableQuery: function(tableName, schema, schemaDelimiter) {
var table = this.quoteTable(
this.addSchema({
......
......@@ -83,6 +83,10 @@ module.exports = (function() {
}
};
AbstractQuery.prototype.isVersionQuery = function () {
return this.options.type === QueryTypes.VERSION;
};
AbstractQuery.prototype.isUpsertQuery = function () {
return this.options.type === QueryTypes.UPSERT;
};
......
......@@ -17,6 +17,10 @@ module.exports = (function() {
return 'SHOW TABLES';
},
versionQuery: function() {
return 'SELECT VERSION() as `version`';
},
createTableQuery: function(tableName, attributes, options) {
options = Utils._.extend({
engine: 'InnoDB',
......
......@@ -97,6 +97,8 @@ module.exports = (function() {
result = data[0];
} else if (this.isBulkUpdateQuery() || this.isBulkDeleteQuery() || this.isUpsertQuery()) {
result = data.affectedRows;
} else if (this.isVersionQuery()) {
result = data[0].version;
}
return result;
......
......@@ -28,6 +28,10 @@ module.exports = (function() {
return "SELECT schema_name FROM information_schema.schemata WHERE schema_name <> 'information_schema' AND schema_name != 'public' AND schema_name !~ E'^pg_';";
},
versionQuery: function() {
return 'SELECT VERSION() as "version"';
},
createTableQuery: function(tableName, attributes, options) {
var self = this;
......
......@@ -234,6 +234,8 @@ module.exports = (function() {
}
return self.callee || (rows && rows[0]) || undefined;
} else if (self.isVersionQuery()) {
return results[0].version;
} else {
return results;
}
......
......@@ -28,6 +28,10 @@ module.exports = (function() {
return "SELECT name FROM `sqlite_master` WHERE type='table' and name!='sqlite_sequence';";
},
versionQuery: function() {
return "SELECT sqlite_version() as `version`";
},
createTableQuery: function(tableName, attributes, options) {
options = options || {};
......
......@@ -137,6 +137,8 @@ module.exports = (function() {
result = metaData.changes;
} else if (self.options.type === QueryTypes.UPSERT) {
result = undefined;
} else if (self.options.type === QueryTypes.VERSION) {
result = results[0].version;
}
resolve(result);
......
......@@ -61,6 +61,13 @@ module.exports = (function() {
});
};
QueryInterface.prototype.databaseVersion = function() {
return this.sequelize.query(this.QueryGenerator.versionQuery(), null, {
raw: true,
type: QueryTypes.VERSION
});
};
QueryInterface.prototype.createTable = function(tableName, attributes, options) {
var keys = Object.keys(attributes)
, keyLen = keys.length
......
......@@ -6,4 +6,5 @@ module.exports = {
BULKUPDATE: 'BULKUPDATE',
BULKDELETE: 'BULKDELETE',
UPSERT: 'UPSERT',
VERSION: 'VERSION'
};
......@@ -787,6 +787,10 @@ module.exports = (function() {
});
};
Sequelize.prototype.databaseVersion = function() {
return this.queryInterface.databaseVersion();
};
Sequelize.prototype.validate = Sequelize.prototype.authenticate;
/**
......
......@@ -1118,4 +1118,13 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
}
})
})
describe('databaseVersion', function () {
it('should database/dialect version', function () {
return this.sequelize.databaseVersion().then(function (version) {
expect(typeof version).to.equal('string');
expect(version).to.be.ok;
});
});
});
});
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!