Create feature base function
This commit is contained in:
parent
70db124033
commit
3d20971709
19
lib/sql.js
19
lib/sql.js
|
@ -1185,18 +1185,11 @@ SQLConnector.prototype.buildOrderBy = function(model, order) {
|
|||
return '';
|
||||
}
|
||||
var self = this;
|
||||
var supportedConnectors = ['mysql', 'postgresql', 'oracle', 'mssql'];
|
||||
var usedConnector = this.dataSource.connector.name;
|
||||
|
||||
if (order === 'rand') {
|
||||
if (usedConnector === 'mysql') {
|
||||
return 'ORDER BY RAND()';
|
||||
} else if (usedConnector === 'postgres') {
|
||||
return 'ORDER BY RANDOM()';
|
||||
} else if (usedConnector === 'oracle') {
|
||||
return 'ORDER BY dbms_random.value';
|
||||
} else if (usedConnector === 'mssql') {
|
||||
return 'ORDER BY NEWID()';
|
||||
}
|
||||
if (order === '${random}') {
|
||||
if (supportedConnectors.indexOf(usedConnector) > -1) return this.buildOrderByRandom();
|
||||
else throw new Error(g.f('feature is not supported yet by this connector'));
|
||||
} else {
|
||||
if (typeof order === 'string') {
|
||||
order = [order];
|
||||
|
@ -1214,6 +1207,10 @@ SQLConnector.prototype.buildOrderBy = function(model, order) {
|
|||
return 'ORDER BY ' + clauses.join(',');
|
||||
};
|
||||
|
||||
SQLConnector.prototype.buildOrderByRandom = function() {
|
||||
throw new Error(g.f('{{buildOrderByRandom()}} must be implemented by the connector'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an array of fields for the database operation
|
||||
* @param {String} model Model name
|
||||
|
|
Loading…
Reference in New Issue