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

Commit 3107396d by Felix Becker Committed by Jan Aagaard Meier

ES6 refactor: dialects / PostgreSQL (#6048)

* ES6 refactor of hstore.js

const, export

* ES6 refactor of PostgresDialect

const, classes, property shorthands, export default

* ES6 refactor of postgres ConnectionManager

classes, let, const, arrow functions, for of, export default

* Make postgres Query an ES6 class

* ES6 refactor of postgres Query

let, const, arrow functions, property shorthands, export default

* ES6 refactor of postgres QueryGenerator

let, const, arrow functions, template strings where it was easy to implement

* ES6 refactor of postgres range.js

let, const, arrow functions, export
1 parent 3e911332
'use strict';
var hstore = require('pg-hstore')({sanitize : true});
const hstore = require('pg-hstore')({sanitize : true});
function stringify (data) {
if (data === null) return null;
return hstore.stringify(data);
}
exports.stringify = stringify;
function parse (value) {
if (value === null) return null;
return hstore.parse(value);
}
module.exports = {
stringify: stringify,
parse: parse
};
exports.parse = parse;
'use strict';
var _ = require('lodash')
, Abstract = require('../abstract')
, ConnectionManager = require('./connection-manager')
, Query = require('./query')
, QueryGenerator = require('./query-generator')
, DataTypes = require('../../data-types').postgres;
const _ = require('lodash');
const AbstractDialect = require('../abstract');
const ConnectionManager = require('./connection-manager');
const Query = require('./query');
const QueryGenerator = require('./query-generator');
const DataTypes = require('../../data-types').postgres;
var PostgresDialect = function(sequelize) {
this.sequelize = sequelize;
this.connectionManager = new ConnectionManager(this, sequelize);
this.connectionManager.initPools();
class PostgresDialect extends AbstractDialect {
constructor(sequelize) {
super();
this.sequelize = sequelize;
this.connectionManager = new ConnectionManager(this, sequelize);
this.connectionManager.initPools();
this.QueryGenerator = _.extend({}, QueryGenerator, {
options: sequelize.options,
_dialect: this,
sequelize: sequelize
});
};
this.QueryGenerator = _.extend({}, QueryGenerator, {
options: sequelize.options,
_dialect: this,
sequelize
});
}
}
PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supports), {
PostgresDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.supports), {
'DEFAULT VALUES': true,
'EXCEPTION': true,
'ON DUPLICATE KEY': false,
......@@ -59,3 +62,5 @@ PostgresDialect.prototype.TICK_CHAR_LEFT = PostgresDialect.prototype.TICK_CHAR;
PostgresDialect.prototype.TICK_CHAR_RIGHT = PostgresDialect.prototype.TICK_CHAR;
module.exports = PostgresDialect;
module.exports.default = PostgresDialect;
module.exports.PostgresDialect = PostgresDialect;
'use strict';
var _ = require('lodash');
const _ = require('lodash');
function stringifyRangeBound (bound) {
if (bound === null) {
......@@ -39,44 +39,38 @@ function stringify (data) {
data.inclusive = [true, false];
}
_.each(data, function (value, index) {
_.each(data, (value, index) => {
if (_.isObject(value)) {
if (value.hasOwnProperty('inclusive')) data.inclusive[index] = !!value.inclusive;
if (value.hasOwnProperty('value')) data[index] = value.value;
}
});
var lowerBound = stringifyRangeBound(data[0]);
var upperBound = stringifyRangeBound(data[1]);
const lowerBound = stringifyRangeBound(data[0]);
const upperBound = stringifyRangeBound(data[1]);
return (data.inclusive[0] ? '[' : '(') + lowerBound + ',' + upperBound + (data.inclusive[1] ? ']' : ')');
}
exports.stringify = stringify;
function parse (value, parser) {
if (value === null) return null;
if (value === 'empty') {
var empty = [];
const empty = [];
empty.inclusive = [];
return empty;
}
var result = value
let result = value
.substring(1, value.length - 1)
.split(',', 2);
if (result.length !== 2) return value;
result = result
.map(function (value) {
return parseRangeBound(value, parser);
});
result = result.map(value => parseRangeBound(value, parser));
result.inclusive = [(value[0] === '['), (value[value.length - 1] === ']')];
return result;
}
module.exports = {
stringify: stringify,
parse: parse
};
exports.parse = parse;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!