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 a0e244f9
authored
Apr 24, 2020
by
Simon Schick
Committed by
GitHub
Apr 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use native versions (#12159)
1 parent
c130d070
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
15 additions
and
49 deletions
docs/manual-utils.js
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/errors/association-error.js
lib/errors/base-error.js
lib/errors/bulk-record-error.js
lib/errors/connection-error.js
lib/errors/connection/access-denied-error.js
lib/errors/connection/connection-acquire-timeout-error.js
lib/errors/connection/connection-refused-error.js
lib/errors/connection/connection-timed-out-error.js
lib/errors/connection/host-not-found-error.js
lib/errors/connection/host-not-reachable-error.js
lib/errors/connection/invalid-connection-error.js
lib/errors/database-error.js
lib/errors/database/exclusion-constraint-error.js
lib/errors/database/foreign-key-constraint-error.js
lib/errors/database/timeout-error.js
lib/errors/database/unknown-constraint-error.js
lib/errors/eager-loading-error.js
lib/errors/empty-result-error.js
lib/errors/instance-error.js
lib/errors/optimistic-lock-error.js
lib/errors/query-error.js
lib/errors/sequelize-scope-error.js
lib/errors/validation-error.js
lib/errors/validation/unique-constraint-error.js
lib/instance-validator.js
lib/query-interface.js
lib/utils.js
test/integration/associations/self.test.js
test/integration/model/create.test.js
docs/manual-utils.js
View file @
a0e244f
...
@@ -7,7 +7,7 @@ const assert = require('assert');
...
@@ -7,7 +7,7 @@ const assert = require('assert');
function
getDeclaredManuals
()
{
function
getDeclaredManuals
()
{
const
declaredManualGroups
=
require
(
'./manual-groups.json'
);
const
declaredManualGroups
=
require
(
'./manual-groups.json'
);
return
_
.
flatten
(
_
.
values
(
declaredManualGroups
)).
map
(
file
=>
{
return
_
.
flatten
(
Object
.
values
(
declaredManualGroups
)).
map
(
file
=>
{
return
normalize
(
`./docs/manual/
${
file
}
`
);
return
normalize
(
`./docs/manual/
${
file
}
`
);
});
});
}
}
...
...
lib/associations/mixin.js
View file @
a0e244f
...
@@ -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
)
{
...
...
lib/data-types.js
View file @
a0e244f
...
@@ -1041,7 +1041,7 @@ dialectMap.mariadb = require('./dialects/mariadb/data-types')(DataTypes);
...
@@ -1041,7 +1041,7 @@ dialectMap.mariadb = require('./dialects/mariadb/data-types')(DataTypes);
dialectMap
.
sqlite
=
require
(
'./dialects/sqlite/data-types'
)(
DataTypes
);
dialectMap
.
sqlite
=
require
(
'./dialects/sqlite/data-types'
)(
DataTypes
);
dialectMap
.
mssql
=
require
(
'./dialects/mssql/data-types'
)(
DataTypes
);
dialectMap
.
mssql
=
require
(
'./dialects/mssql/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
)
=>
{
...
...
lib/dialects/abstract/query.js
View file @
a0e244f
...
@@ -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
()
{
...
...
lib/dialects/postgres/query-generator.js
View file @
a0e244f
...
@@ -384,7 +384,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
...
@@ -384,7 +384,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
;
...
@@ -840,10 +840,6 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
...
@@ -840,10 +840,6 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
return
matches
.
slice
(
0
,
-
1
);
return
matches
.
slice
(
0
,
-
1
);
}
}
padInt
(
i
)
{
return
i
<
10
?
`0
${
i
.
toString
()}
`
:
i
.
toString
();
}
dataTypeMapping
(
tableName
,
attr
,
dataType
)
{
dataTypeMapping
(
tableName
,
attr
,
dataType
)
{
if
(
dataType
.
includes
(
'PRIMARY KEY'
))
{
if
(
dataType
.
includes
(
'PRIMARY KEY'
))
{
dataType
=
dataType
.
replace
(
'PRIMARY KEY'
,
''
);
dataType
=
dataType
.
replace
(
'PRIMARY KEY'
,
''
);
...
...
lib/dialects/postgres/query.js
View file @
a0e244f
...
@@ -121,7 +121,7 @@ class Query extends AbstractQuery {
...
@@ -121,7 +121,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
)
{
...
...
lib/dialects/sqlite/query-generator.js
View file @
a0e244f
...
@@ -23,7 +23,7 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
...
@@ -23,7 +23,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
)
{
...
...
lib/errors/association-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class AssociationError extends BaseError {
...
@@ -9,7 +9,6 @@ class AssociationError extends BaseError {
constructor
(
message
)
{
constructor
(
message
)
{
super
(
message
);
super
(
message
);
this
.
name
=
'SequelizeAssociationError'
;
this
.
name
=
'SequelizeAssociationError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/base-error.js
View file @
a0e244f
...
@@ -11,7 +11,6 @@ class BaseError extends Error {
...
@@ -11,7 +11,6 @@ class BaseError extends Error {
constructor
(
message
)
{
constructor
(
message
)
{
super
(
message
);
super
(
message
);
this
.
name
=
'SequelizeBaseError'
;
this
.
name
=
'SequelizeBaseError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/bulk-record-error.js
View file @
a0e244f
...
@@ -15,7 +15,6 @@ class BulkRecordError extends BaseError {
...
@@ -15,7 +15,6 @@ class BulkRecordError extends BaseError {
this
.
name
=
'SequelizeBulkRecordError'
;
this
.
name
=
'SequelizeBulkRecordError'
;
this
.
errors
=
error
;
this
.
errors
=
error
;
this
.
record
=
record
;
this
.
record
=
record
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection-error.js
View file @
a0e244f
...
@@ -16,7 +16,6 @@ class ConnectionError extends BaseError {
...
@@ -16,7 +16,6 @@ class ConnectionError extends BaseError {
*/
*/
this
.
parent
=
parent
;
this
.
parent
=
parent
;
this
.
original
=
parent
;
this
.
original
=
parent
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection/access-denied-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class AccessDeniedError extends ConnectionError {
...
@@ -9,7 +9,6 @@ class AccessDeniedError extends ConnectionError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeAccessDeniedError'
;
this
.
name
=
'SequelizeAccessDeniedError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection/connection-acquire-timeout-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class ConnectionAcquireTimeoutError extends ConnectionError {
...
@@ -9,7 +9,6 @@ class ConnectionAcquireTimeoutError extends ConnectionError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeConnectionAcquireTimeoutError'
;
this
.
name
=
'SequelizeConnectionAcquireTimeoutError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection/connection-refused-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class ConnectionRefusedError extends ConnectionError {
...
@@ -9,7 +9,6 @@ class ConnectionRefusedError extends ConnectionError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeConnectionRefusedError'
;
this
.
name
=
'SequelizeConnectionRefusedError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection/connection-timed-out-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class ConnectionTimedOutError extends ConnectionError {
...
@@ -9,7 +9,6 @@ class ConnectionTimedOutError extends ConnectionError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeConnectionTimedOutError'
;
this
.
name
=
'SequelizeConnectionTimedOutError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection/host-not-found-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class HostNotFoundError extends ConnectionError {
...
@@ -9,7 +9,6 @@ class HostNotFoundError extends ConnectionError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeHostNotFoundError'
;
this
.
name
=
'SequelizeHostNotFoundError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection/host-not-reachable-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class HostNotReachableError extends ConnectionError {
...
@@ -9,7 +9,6 @@ class HostNotReachableError extends ConnectionError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeHostNotReachableError'
;
this
.
name
=
'SequelizeHostNotReachableError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/connection/invalid-connection-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class InvalidConnectionError extends ConnectionError {
...
@@ -9,7 +9,6 @@ class InvalidConnectionError extends ConnectionError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeInvalidConnectionError'
;
this
.
name
=
'SequelizeInvalidConnectionError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/database-error.js
View file @
a0e244f
...
@@ -29,7 +29,6 @@ class DatabaseError extends BaseError {
...
@@ -29,7 +29,6 @@ class DatabaseError extends BaseError {
* @type {Array<any>}
* @type {Array<any>}
*/
*/
this
.
parameters
=
parent
.
parameters
;
this
.
parameters
=
parent
.
parameters
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/database/exclusion-constraint-error.js
View file @
a0e244f
...
@@ -17,7 +17,6 @@ class ExclusionConstraintError extends DatabaseError {
...
@@ -17,7 +17,6 @@ class ExclusionConstraintError extends DatabaseError {
this
.
constraint
=
options
.
constraint
;
this
.
constraint
=
options
.
constraint
;
this
.
fields
=
options
.
fields
;
this
.
fields
=
options
.
fields
;
this
.
table
=
options
.
table
;
this
.
table
=
options
.
table
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/database/foreign-key-constraint-error.js
View file @
a0e244f
...
@@ -19,7 +19,6 @@ class ForeignKeyConstraintError extends DatabaseError {
...
@@ -19,7 +19,6 @@ class ForeignKeyConstraintError extends DatabaseError {
this
.
value
=
options
.
value
;
this
.
value
=
options
.
value
;
this
.
index
=
options
.
index
;
this
.
index
=
options
.
index
;
this
.
reltype
=
options
.
reltype
;
this
.
reltype
=
options
.
reltype
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/database/timeout-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class TimeoutError extends DatabaseError {
...
@@ -9,7 +9,6 @@ class TimeoutError extends DatabaseError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeTimeoutError'
;
this
.
name
=
'SequelizeTimeoutError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/database/unknown-constraint-error.js
View file @
a0e244f
...
@@ -17,7 +17,6 @@ class UnknownConstraintError extends DatabaseError {
...
@@ -17,7 +17,6 @@ class UnknownConstraintError extends DatabaseError {
this
.
constraint
=
options
.
constraint
;
this
.
constraint
=
options
.
constraint
;
this
.
fields
=
options
.
fields
;
this
.
fields
=
options
.
fields
;
this
.
table
=
options
.
table
;
this
.
table
=
options
.
table
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/eager-loading-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class EagerLoadingError extends BaseError {
...
@@ -9,7 +9,6 @@ class EagerLoadingError extends BaseError {
constructor
(
message
)
{
constructor
(
message
)
{
super
(
message
);
super
(
message
);
this
.
name
=
'SequelizeEagerLoadingError'
;
this
.
name
=
'SequelizeEagerLoadingError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/empty-result-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class EmptyResultError extends BaseError {
...
@@ -9,7 +9,6 @@ class EmptyResultError extends BaseError {
constructor
(
message
)
{
constructor
(
message
)
{
super
(
message
);
super
(
message
);
this
.
name
=
'SequelizeEmptyResultError'
;
this
.
name
=
'SequelizeEmptyResultError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/instance-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class InstanceError extends BaseError {
...
@@ -9,7 +9,6 @@ class InstanceError extends BaseError {
constructor
(
message
)
{
constructor
(
message
)
{
super
(
message
);
super
(
message
);
this
.
name
=
'SequelizeInstanceError'
;
this
.
name
=
'SequelizeInstanceError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/optimistic-lock-error.js
View file @
a0e244f
...
@@ -28,7 +28,6 @@ class OptimisticLockError extends BaseError {
...
@@ -28,7 +28,6 @@ class OptimisticLockError extends BaseError {
* @type {object}
* @type {object}
*/
*/
this
.
where
=
options
.
where
;
this
.
where
=
options
.
where
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/query-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class QueryError extends BaseError {
...
@@ -9,7 +9,6 @@ class QueryError extends BaseError {
constructor
(
message
)
{
constructor
(
message
)
{
super
(
message
);
super
(
message
);
this
.
name
=
'SequelizeQueryError'
;
this
.
name
=
'SequelizeQueryError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/sequelize-scope-error.js
View file @
a0e244f
...
@@ -9,7 +9,6 @@ class SequelizeScopeError extends BaseError {
...
@@ -9,7 +9,6 @@ class SequelizeScopeError extends BaseError {
constructor
(
parent
)
{
constructor
(
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
name
=
'SequelizeScopeError'
;
this
.
name
=
'SequelizeScopeError'
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/errors/validation-error.js
View file @
a0e244f
...
@@ -30,7 +30,6 @@ class ValidationError extends BaseError {
...
@@ -30,7 +30,6 @@ class ValidationError extends BaseError {
}
else
if
(
this
.
errors
.
length
>
0
&&
this
.
errors
[
0
].
message
)
{
}
else
if
(
this
.
errors
.
length
>
0
&&
this
.
errors
[
0
].
message
)
{
this
.
message
=
this
.
errors
.
map
(
err
=>
`
${
err
.
type
||
err
.
origin
}
:
${
err
.
message
}
`
).
join
(
',\n'
);
this
.
message
=
this
.
errors
.
map
(
err
=>
`
${
err
.
type
||
err
.
origin
}
:
${
err
.
message
}
`
).
join
(
',\n'
);
}
}
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
/**
/**
...
...
lib/errors/validation/unique-constraint-error.js
View file @
a0e244f
...
@@ -19,7 +19,6 @@ class UniqueConstraintError extends ValidationError {
...
@@ -19,7 +19,6 @@ class UniqueConstraintError extends ValidationError {
this
.
parent
=
options
.
parent
;
this
.
parent
=
options
.
parent
;
this
.
original
=
options
.
parent
;
this
.
original
=
options
.
parent
;
this
.
sql
=
options
.
parent
.
sql
;
this
.
sql
=
options
.
parent
.
sql
;
Error
.
captureStackTrace
(
this
,
this
.
constructor
);
}
}
}
}
...
...
lib/instance-validator.js
View file @
a0e244f
...
@@ -344,7 +344,7 @@ class InstanceValidator {
...
@@ -344,7 +344,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`
);
...
...
lib/query-interface.js
View file @
a0e244f
...
@@ -556,7 +556,7 @@ class QueryInterface {
...
@@ -556,7 +556,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
;
...
...
lib/utils.js
View file @
a0e244f
...
@@ -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'
);
...
...
test/integration/associations/self.test.js
View file @
a0e244f
...
@@ -5,8 +5,7 @@ const chai = require('chai'),
...
@@ -5,8 +5,7 @@ const chai = require('chai'),
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
Sequelize
=
require
(
'../../../index'
),
Sequelize
=
require
(
'../../../index'
),
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 +51,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
...
@@ -52,7 +51,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 +93,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
...
@@ -94,7 +93,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
);
...
...
test/integration/model/create.test.js
View file @
a0e244f
...
@@ -925,13 +925,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -925,13 +925,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return
userWithDefaults
.
sync
({
force
:
true
}).
then
(()
=>
{
return
userWithDefaults
.
sync
({
force
:
true
}).
then
(()
=>
{
return
userWithDefaults
.
create
({}).
then
(
user
=>
{
return
userWithDefaults
.
create
({}).
then
(
user
=>
{
return
userWithDefaults
.
findByPk
(
user
.
id
).
then
(
user
=>
{
return
userWithDefaults
.
findByPk
(
user
.
id
).
then
(
user
=>
{
const
now
=
new
Date
(),
const
now
=
new
Date
();
pad
=
function
(
number
)
{
const
pad
=
number
=>
number
.
toString
().
padStart
(
2
,
'0'
);
if
(
number
>
9
)
{
return
number
;
}
return
`0
${
number
}
`
;
};
expect
(
user
.
year
).
to
.
equal
(
`
${
now
.
getUTCFullYear
()}
-
${
pad
(
now
.
getUTCMonth
()
+
1
)}
-
${
pad
(
now
.
getUTCDate
())}
`
);
expect
(
user
.
year
).
to
.
equal
(
`
${
now
.
getUTCFullYear
()}
-
${
pad
(
now
.
getUTCMonth
()
+
1
)}
-
${
pad
(
now
.
getUTCDate
())}
`
);
});
});
...
...
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