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

Commit ed9bf350 by Simon Schick

refactor: use native Object.values

1 parent dcf079b2
...@@ -75,7 +75,7 @@ const Mixin = { ...@@ -75,7 +75,7 @@ const Mixin = {
}, },
getAssociations(target) { getAssociations(target) {
return _.values(this.associations).filter(association => association.target.name === target.name); return Object.values(this.associations).filter(association => association.target.name === target.name);
}, },
getAssociationForAlias(target, alias) { getAssociationForAlias(target, alias) {
......
...@@ -1032,7 +1032,7 @@ const dialectMap = {}; ...@@ -1032,7 +1032,7 @@ const dialectMap = {};
for (const d of dialectNames) { for (const d of dialectNames) {
dialectMap[d] = require(`./dialects/${d}/data-types`)(DataTypes); dialectMap[d] = require(`./dialects/${d}/data-types`)(DataTypes);
} }
const dialectList = _.values(dialectMap); const dialectList = Object.values(dialectMap);
for (const dataTypes of dialectList) { for (const dataTypes of dialectList) {
_.each(dataTypes, (DataType, key) => { _.each(dataTypes, (DataType, key) => {
......
...@@ -206,7 +206,7 @@ class AbstractQuery { ...@@ -206,7 +206,7 @@ class AbstractQuery {
} }
handleShowTablesQuery(results) { handleShowTablesQuery(results) {
return _.flatten(results.map(resultSet => _.values(resultSet))); return _.flatten(results.map(resultSet => Object.values(resultSet)));
} }
isShowIndexesQuery() { isShowIndexesQuery() {
......
...@@ -383,7 +383,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { ...@@ -383,7 +383,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
throw new Error('Cannot LIMIT delete without a model.'); throw new Error('Cannot LIMIT delete without a model.');
} }
const pks = _.values(model.primaryKeys).map(pk => this.quoteIdentifier(pk.field)).join(','); const pks = Object.values(model.primaryKeys).map(pk => this.quoteIdentifier(pk.field)).join(',');
primaryKeys = model.primaryKeyAttributes.length > 1 ? `(${pks})` : pks; primaryKeys = model.primaryKeyAttributes.length > 1 ? `(${pks})` : pks;
primaryKeysSelection = pks; primaryKeysSelection = pks;
......
...@@ -93,7 +93,7 @@ class Query extends AbstractQuery { ...@@ -93,7 +93,7 @@ class Query extends AbstractQuery {
})); }));
} }
if (isTableNameQuery) { if (isTableNameQuery) {
return rows.map(row => _.values(row)); return rows.map(row => Object.values(row));
} }
if (rows[0] && rows[0].sequelize_caught_exception !== undefined) { if (rows[0] && rows[0].sequelize_caught_exception !== undefined) {
......
...@@ -24,7 +24,7 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator { ...@@ -24,7 +24,7 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
options = options || {}; options = options || {};
const primaryKeys = []; const primaryKeys = [];
const needsMultiplePrimaryKeys = _.values(attributes).filter(definition => definition.includes('PRIMARY KEY')).length > 1; const needsMultiplePrimaryKeys = Object.values(attributes).filter(definition => definition.includes('PRIMARY KEY')).length > 1;
const attrArray = []; const attrArray = [];
for (const attr in attributes) { for (const attr in attributes) {
......
...@@ -337,7 +337,7 @@ class InstanceValidator { ...@@ -337,7 +337,7 @@ class InstanceValidator {
*/ */
_validateSchema(rawAttribute, field, value) { _validateSchema(rawAttribute, field, value) {
if (rawAttribute.allowNull === false && (value === null || value === undefined)) { if (rawAttribute.allowNull === false && (value === null || value === undefined)) {
const association = _.values(this.modelInstance.constructor.associations).find(association => association instanceof BelongsTo && association.foreignKey === rawAttribute.fieldName); const association = Object.values(this.modelInstance.constructor.associations).find(association => association instanceof BelongsTo && association.foreignKey === rawAttribute.fieldName);
if (!association || !this.modelInstance.get(association.associationAccessor)) { if (!association || !this.modelInstance.get(association.associationAccessor)) {
const validators = this.modelInstance.validators[field]; const validators = this.modelInstance.validators[field];
const errMsg = _.get(validators, 'notNull.msg', `${this.modelInstance.constructor.name}.${field} cannot be null`); const errMsg = _.get(validators, 'notNull.msg', `${this.modelInstance.constructor.name}.${field} cannot be null`);
......
...@@ -555,7 +555,7 @@ class QueryInterface { ...@@ -555,7 +555,7 @@ class QueryInterface {
const attributes = {}; const attributes = {};
options = options || {}; options = options || {};
if (_.values(DataTypes).includes(dataTypeOrOptions)) { if (Object.values(DataTypes).includes(dataTypeOrOptions)) {
attributes[attributeName] = { type: dataTypeOrOptions, allowNull: true }; attributes[attributeName] = { type: dataTypeOrOptions, allowNull: true };
} else { } else {
attributes[attributeName] = dataTypeOrOptions; attributes[attributeName] = dataTypeOrOptions;
......
...@@ -7,7 +7,7 @@ const uuidv1 = require('uuid/v1'); ...@@ -7,7 +7,7 @@ const uuidv1 = require('uuid/v1');
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
const Promise = require('./promise'); const Promise = require('./promise');
const operators = require('./operators'); const operators = require('./operators');
const operatorsSet = new Set(_.values(operators)); const operatorsSet = new Set(Object.values(operators));
let inflection = require('inflection'); let inflection = require('inflection');
......
'use strict'; 'use strict';
const chai = require('chai'), const { expect } = require('chai');
expect = chai.expect, const Support = require('../support');
Support = require('../support'), const DataTypes = require('../../../lib/data-types');
DataTypes = require('../../../lib/data-types'), const Sequelize = require('../../../index');
Sequelize = require('../../../index'), const Promise = Sequelize.Promise;
Promise = Sequelize.Promise,
_ = require('lodash');
describe(Support.getTestDialectTeaser('Self'), () => { describe(Support.getTestDialectTeaser('Self'), () => {
it('supports freezeTableName', function() { it('supports freezeTableName', function() {
...@@ -52,7 +50,7 @@ describe(Support.getTestDialectTeaser('Self'), () => { ...@@ -52,7 +50,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
Person.belongsToMany(Person, { as: 'Parents', through: 'Family', foreignKey: 'ChildId', otherKey: 'PersonId' }); Person.belongsToMany(Person, { as: 'Parents', through: 'Family', foreignKey: 'ChildId', otherKey: 'PersonId' });
Person.belongsToMany(Person, { as: 'Childs', through: 'Family', foreignKey: 'PersonId', otherKey: 'ChildId' }); Person.belongsToMany(Person, { as: 'Childs', through: 'Family', foreignKey: 'PersonId', otherKey: 'ChildId' });
const foreignIdentifiers = _.values(Person.associations).map(v => v.foreignIdentifier); const foreignIdentifiers = Object.values(Person.associations).map(v => v.foreignIdentifier);
const rawAttributes = Object.keys(this.sequelize.models.Family.rawAttributes); const rawAttributes = Object.keys(this.sequelize.models.Family.rawAttributes);
expect(foreignIdentifiers.length).to.equal(2); expect(foreignIdentifiers.length).to.equal(2);
...@@ -94,7 +92,7 @@ describe(Support.getTestDialectTeaser('Self'), () => { ...@@ -94,7 +92,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
Person.belongsToMany(Person, { as: 'Parents', through: Family, foreignKey: 'preexisting_child', otherKey: 'preexisting_parent' }); Person.belongsToMany(Person, { as: 'Parents', through: Family, foreignKey: 'preexisting_child', otherKey: 'preexisting_parent' });
Person.belongsToMany(Person, { as: 'Children', through: Family, foreignKey: 'preexisting_parent', otherKey: 'preexisting_child' }); Person.belongsToMany(Person, { as: 'Children', through: Family, foreignKey: 'preexisting_parent', otherKey: 'preexisting_child' });
const foreignIdentifiers = _.values(Person.associations).map(v => v.foreignIdentifier); const foreignIdentifiers = Object.values(Person.associations).map(v => v.foreignIdentifier);
const rawAttributes = Object.keys(Family.rawAttributes); const rawAttributes = Object.keys(Family.rawAttributes);
expect(foreignIdentifiers.length).to.equal(2); expect(foreignIdentifiers.length).to.equal(2);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!