Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit ed9bf350
authored
Mar 23, 2019
by
Simon Schick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use native Object.values
1 parent
dcf079b2
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
16 additions
and
18 deletions
lib/associations/mixin.js
lib/data-types.js
lib/dialects/abstract/query.js
lib/dialects/postgres/query-generator.js
lib/dialects/postgres/query.js
lib/dialects/sqlite/query-generator.js
lib/instance-validator.js
lib/query-interface.js
lib/utils.js
test/integration/associations/self.test.js
lib/associations/mixin.js
View file @
ed9bf35
...
...
@@ -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
)
{
...
...
lib/data-types.js
View file @
ed9bf35
...
...
@@ -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
)
=>
{
...
...
lib/dialects/abstract/query.js
View file @
ed9bf35
...
...
@@ -206,7 +206,7 @@ class AbstractQuery {
}
handleShowTablesQuery
(
results
)
{
return
_
.
flatten
(
results
.
map
(
resultSet
=>
_
.
values
(
resultSet
)));
return
_
.
flatten
(
results
.
map
(
resultSet
=>
Object
.
values
(
resultSet
)));
}
isShowIndexesQuery
()
{
...
...
lib/dialects/postgres/query-generator.js
View file @
ed9bf35
...
...
@@ -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
;
...
...
lib/dialects/postgres/query.js
View file @
ed9bf35
...
...
@@ -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
)
{
...
...
lib/dialects/sqlite/query-generator.js
View file @
ed9bf35
...
...
@@ -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
)
{
...
...
lib/instance-validator.js
View file @
ed9bf35
...
...
@@ -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`
);
...
...
lib/query-interface.js
View file @
ed9bf35
...
...
@@ -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
;
...
...
lib/utils.js
View file @
ed9bf35
...
...
@@ -7,7 +7,7 @@ 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
operatorsSet
=
new
Set
(
Object
.
values
(
operators
));
let
inflection
=
require
(
'inflection'
);
...
...
test/integration/associations/self.test.js
View file @
ed9bf35
'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
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment