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

Commit ed9bf350 by Simon Schick

refactor: use native Object.values

1 parent dcf079b2
......@@ -75,7 +75,7 @@ const Mixin = {
},
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) {
......
......@@ -1032,7 +1032,7 @@ const dialectMap = {};
for (const d of dialectNames) {
dialectMap[d] = require(`./dialects/${d}/data-types`)(DataTypes);
}
const dialectList = _.values(dialectMap);
const dialectList = Object.values(dialectMap);
for (const dataTypes of dialectList) {
_.each(dataTypes, (DataType, key) => {
......
......@@ -206,7 +206,7 @@ class AbstractQuery {
}
handleShowTablesQuery(results) {
return _.flatten(results.map(resultSet => _.values(resultSet)));
return _.flatten(results.map(resultSet => Object.values(resultSet)));
}
isShowIndexesQuery() {
......
......@@ -383,7 +383,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
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;
primaryKeysSelection = pks;
......
......@@ -93,7 +93,7 @@ class Query extends AbstractQuery {
}));
}
if (isTableNameQuery) {
return rows.map(row => _.values(row));
return rows.map(row => Object.values(row));
}
if (rows[0] && rows[0].sequelize_caught_exception !== undefined) {
......
......@@ -24,7 +24,7 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
options = options || {};
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 = [];
for (const attr in attributes) {
......
......@@ -337,7 +337,7 @@ class InstanceValidator {
*/
_validateSchema(rawAttribute, field, value) {
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)) {
const validators = this.modelInstance.validators[field];
const errMsg = _.get(validators, 'notNull.msg', `${this.modelInstance.constructor.name}.${field} cannot be null`);
......
......@@ -555,7 +555,7 @@ class QueryInterface {
const attributes = {};
options = options || {};
if (_.values(DataTypes).includes(dataTypeOrOptions)) {
if (Object.values(DataTypes).includes(dataTypeOrOptions)) {
attributes[attributeName] = { type: dataTypeOrOptions, allowNull: true };
} else {
attributes[attributeName] = dataTypeOrOptions;
......
......@@ -6,8 +6,8 @@ const _ = require('lodash');
const uuidv1 = require('uuid/v1');
const uuidv4 = require('uuid/v4');
const Promise = require('./promise');
const operators = require('./operators');
const operatorsSet = new Set(_.values(operators));
const operators = require('./operators');
const operatorsSet = new Set(Object.values(operators));
let inflection = require('inflection');
......
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require('../support'),
DataTypes = require('../../../lib/data-types'),
Sequelize = require('../../../index'),
Promise = Sequelize.Promise,
_ = require('lodash');
const { expect } = require('chai');
const Support = require('../support');
const DataTypes = require('../../../lib/data-types');
const Sequelize = require('../../../index');
const Promise = Sequelize.Promise;
describe(Support.getTestDialectTeaser('Self'), () => {
it('supports freezeTableName', function() {
......@@ -52,7 +50,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
Person.belongsToMany(Person, { as: 'Parents', through: 'Family', foreignKey: 'ChildId', otherKey: 'PersonId' });
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);
expect(foreignIdentifiers.length).to.equal(2);
......@@ -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: '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);
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!