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 04573fd3
authored
Apr 05, 2020
by
Andy Edwards
Committed by
GitHub
Apr 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: remove bluebird Promise.prototype.return usage (#12065)
1 parent
e0343afe
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
42 additions
and
43 deletions
lib/associations/belongs-to-many.js
lib/associations/has-many.js
lib/dialects/abstract/connection-manager.js
lib/hooks.js
lib/instance-validator.js
lib/model.js
lib/sequelize.js
test/integration/associations/belongs-to-many.test.js
test/integration/associations/has-many.test.js
test/integration/hooks/associations.test.js
test/integration/include.test.js
test/integration/instance/reload.test.js
test/support.js
lib/associations/belongs-to-many.js
View file @
04573fd
...
...
@@ -800,7 +800,7 @@ class BelongsToMany extends Association {
// Create the related model instance
return
association
.
target
.
create
(
values
,
options
).
then
(
newAssociatedObject
=>
sourceInstance
[
association
.
accessors
.
add
](
newAssociatedObject
,
_
.
omit
(
options
,
[
'fields'
])).
return
(
newAssociatedObject
)
sourceInstance
[
association
.
accessors
.
add
](
newAssociatedObject
,
_
.
omit
(
options
,
[
'fields'
])).
then
(()
=>
newAssociatedObject
)
);
}
...
...
lib/associations/has-many.js
View file @
04573fd
...
...
@@ -378,7 +378,7 @@ class HasMany extends Association {
));
}
return
Utils
.
Promise
.
all
(
promises
).
return
(
sourceInstance
);
return
Utils
.
Promise
.
all
(
promises
).
then
(()
=>
sourceInstance
);
});
}
...
...
@@ -408,7 +408,7 @@ class HasMany extends Association {
)
};
return
this
.
target
.
unscoped
().
update
(
update
,
_
.
defaults
({
where
},
options
)).
return
(
sourceInstance
);
return
this
.
target
.
unscoped
().
update
(
update
,
_
.
defaults
({
where
},
options
)).
then
(()
=>
sourceInstance
);
}
/**
...
...
@@ -434,7 +434,7 @@ class HasMany extends Association {
)
};
return
this
.
target
.
unscoped
().
update
(
update
,
_
.
defaults
({
where
},
options
)).
return
(
this
);
return
this
.
target
.
unscoped
().
update
(
update
,
_
.
defaults
({
where
},
options
)).
then
(()
=>
this
);
}
/**
...
...
lib/dialects/abstract/connection-manager.js
View file @
04573fd
...
...
@@ -309,7 +309,7 @@ class ConnectionManager {
_connect
(
config
)
{
return
this
.
sequelize
.
runHooks
(
'beforeConnect'
,
config
)
.
then
(()
=>
this
.
dialect
.
connectionManager
.
connect
(
config
))
.
then
(
connection
=>
this
.
sequelize
.
runHooks
(
'afterConnect'
,
connection
,
config
).
return
(
connection
));
.
then
(
connection
=>
this
.
sequelize
.
runHooks
(
'afterConnect'
,
connection
,
config
).
then
(()
=>
connection
));
}
/**
...
...
lib/hooks.js
View file @
04573fd
...
...
@@ -128,7 +128,7 @@ const Hooks = {
debug
(
`running hook
${
hookType
}
`
);
return
hook
.
apply
(
this
,
hookArgs
);
}).
return
(
);
}).
then
(()
=>
undefined
);
},
/**
...
...
lib/instance-validator.js
View file @
04573fd
...
...
@@ -109,8 +109,7 @@ class InstanceValidator {
.
catch
(
error
=>
runHooks
(
'validationFailed'
,
this
.
modelInstance
,
this
.
options
,
error
)
.
then
(
newError
=>
{
throw
newError
||
error
;
}))
)
.
then
(()
=>
runHooks
(
'afterValidate'
,
this
.
modelInstance
,
this
.
options
))
.
return
(
this
.
modelInstance
);
.
then
(()
=>
runHooks
(
'afterValidate'
,
this
.
modelInstance
,
this
.
options
)).
then
(()
=>
this
.
modelInstance
);
}
/**
...
...
lib/model.js
View file @
04573fd
...
...
@@ -1374,7 +1374,7 @@ class Model {
if
(
options
.
hooks
)
{
return
this
.
runHooks
(
'afterSync'
,
options
);
}
}).
return
(
this
);
}).
then
(()
=>
this
);
}
/**
...
...
@@ -1856,7 +1856,7 @@ class Model {
);
}
});
})).
return
(
original
);
})).
then
(()
=>
original
);
}
/**
...
...
@@ -4357,7 +4357,7 @@ class Model {
options
.
where
=
Object
.
assign
({},
options
.
where
,
identifier
);
options
.
instance
=
this
;
return
this
.
constructor
.
increment
(
fields
,
options
).
return
(
this
);
return
this
.
constructor
.
increment
(
fields
,
options
).
then
(()
=>
this
);
}
/**
...
...
lib/sequelize.js
View file @
04573fd
...
...
@@ -826,7 +826,7 @@ class Sequelize {
if
(
options
.
hooks
)
{
return
this
.
runHooks
(
'afterBulkSync'
,
options
);
}
}).
return
(
this
);
}).
then
(()
=>
this
);
}
/**
...
...
@@ -895,7 +895,7 @@ class Sequelize {
type
:
QueryTypes
.
SELECT
},
options
);
return
this
.
query
(
'SELECT 1+1 AS result'
,
options
).
return
(
);
return
this
.
query
(
'SELECT 1+1 AS result'
,
options
).
then
(()
=>
undefined
);
}
databaseVersion
(
options
)
{
...
...
@@ -1104,7 +1104,7 @@ class Sequelize {
const
transaction
=
new
Transaction
(
this
,
options
);
if
(
!
autoCallback
)
return
transaction
.
prepareEnvironment
(
false
).
return
(
transaction
);
if
(
!
autoCallback
)
return
transaction
.
prepareEnvironment
(
false
).
then
(()
=>
transaction
);
// autoCallback provided
return
Sequelize
.
_clsRun
(()
=>
{
...
...
test/integration/associations/belongs-to-many.test.js
View file @
04573fd
...
...
@@ -1556,7 +1556,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Member
.
create
({
member_id
:
10
,
email
:
'team@sequelizejs.com'
})
]);
}).
then
(([
group
,
member
])
=>
{
return
group
.
addMember
(
member
).
return
(
group
);
return
group
.
addMember
(
member
).
then
(()
=>
group
);
}).
then
(
group
=>
{
return
group
.
getMembers
();
}).
then
(
members
=>
{
...
...
@@ -1728,7 +1728,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Task
.
create
({
id
:
51
,
title
:
'following up'
})
]);
}).
then
(([
user
,
task1
,
task2
])
=>
{
return
user
.
setTasks
([
task1
,
task2
]).
return
(
user
);
return
user
.
setTasks
([
task1
,
task2
]).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
getTasks
();
}).
then
(
userTasks
=>
{
...
...
@@ -1867,7 +1867,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return
Promise
.
all
([
user
.
addTask
(
task1
),
user
.
addTask
([
task2
])
]).
return
(
user
);
]).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
getTasks
();
}).
then
(
tasks
=>
{
...
...
@@ -1965,7 +1965,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Task
.
create
({
id
:
50
,
title
:
'get started'
})
]);
}).
then
(([
user
,
task
])
=>
{
return
user
.
addTask
(
task
.
id
).
return
(
user
);
return
user
.
addTask
(
task
.
id
).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
getTasks
();
}).
then
(
tasks
=>
{
...
...
@@ -2026,7 +2026,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Task
.
create
({
id
:
50
,
title
:
'get started'
})
]);
}).
then
(([
user
,
task
])
=>
{
return
user
.
addTask
(
task
).
return
(
user
);
return
user
.
addTask
(
task
).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
getTasks
();
}).
then
(
tasks
=>
{
...
...
@@ -2074,7 +2074,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return
Promise
.
all
([
user
.
addTasks
(
task1
),
user
.
addTasks
([
task2
])
]).
return
(
user
);
]).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
getTasks
();
}).
then
(
tasks
=>
{
...
...
@@ -2213,7 +2213,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this
.
Task
.
create
({
title
:
'task1'
}),
this
.
Task
.
create
({
title
:
'task2'
})
]).
then
(([
user
,
task1
,
task2
])
=>
{
return
user
.
setTasks
([
task1
,
task2
]).
return
(
user
);
return
user
.
setTasks
([
task1
,
task2
]).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
setTasks
(
null
,
{
logging
:
spy
...
...
@@ -2391,7 +2391,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}).
then
(([
user
,
project1
,
project2
])
=>
{
return
user
.
addProjects
([
project1
,
project2
],
{
logging
:
spy
}).
return
(
user
);
}).
then
(()
=>
user
);
}).
then
(
user
=>
{
expect
(
spy
).
to
.
have
.
been
.
calledTwice
;
spy
.
resetHistory
();
...
...
@@ -2405,7 +2405,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
expect
(
spy
.
calledOnce
).
to
.
be
.
ok
;
const
project
=
projects
[
0
];
expect
(
project
).
to
.
be
.
ok
;
return
project
.
destroy
().
return
(
user
);
return
project
.
destroy
().
then
(()
=>
user
);
}).
then
(
user
=>
{
return
this
.
User
.
findOne
({
where
:
{
id
:
user
.
id
},
...
...
@@ -2429,7 +2429,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}).
then
(([
user
,
project
])
=>
{
this
.
user
=
user
;
this
.
project
=
project
;
return
user
.
addProject
(
project
,
{
logging
:
spy
}).
return
(
user
);
return
user
.
addProject
(
project
,
{
logging
:
spy
}).
then
(()
=>
user
);
}).
then
(
user
=>
{
expect
(
spy
.
calledTwice
).
to
.
be
.
ok
;
// Once for SELECT, once for INSERT
spy
.
resetHistory
();
...
...
@@ -2444,7 +2444,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
expect
(
project
).
to
.
be
.
ok
;
return
this
.
user
.
removeProject
(
project
,
{
logging
:
spy
}).
return
(
project
);
}).
then
(()
=>
project
);
}).
then
(()
=>
{
expect
(
spy
).
to
.
have
.
been
.
calledOnce
;
});
...
...
@@ -2486,7 +2486,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
);
}).
then
(([
group
,
user
,
project
])
=>
{
return
user
.
addProject
(
project
).
then
(()
=>
{
return
group
.
addUser
(
user
).
return
(
group
);
return
group
.
addUser
(
user
).
then
(()
=>
group
);
});
}).
then
(
group
=>
{
// get the group and include both the users in the group and their project's
...
...
@@ -2591,7 +2591,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this
.
User
.
create
({
username
:
'foo'
}),
this
.
Task
.
create
({
title
:
'foo'
})
]).
then
(([
user
,
task
])
=>
{
return
user
.
addTask
(
task
).
return
(
user
);
return
user
.
addTask
(
task
).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
setTasks
(
null
);
}).
then
(
result
=>
{
...
...
@@ -2622,7 +2622,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this
.
User
.
create
(),
this
.
Project
.
create
()
]).
then
(([
user
,
project
])
=>
{
return
user
.
addProject
(
project
,
{
through
:
{
status
:
'active'
,
data
:
42
}
}).
return
(
user
);
return
user
.
addProject
(
project
,
{
through
:
{
status
:
'active'
,
data
:
42
}
}).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
getProjects
();
}).
then
(
projects
=>
{
...
...
@@ -2640,7 +2640,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this
.
User
.
create
(),
this
.
Project
.
create
()
]).
then
(([
user
,
project
])
=>
{
return
user
.
addProject
(
project
,
{
through
:
{
status
:
'active'
,
data
:
42
}
}).
return
(
user
);
return
user
.
addProject
(
project
,
{
through
:
{
status
:
'active'
,
data
:
42
}
}).
then
(()
=>
user
);
}).
then
(()
=>
{
return
this
.
User
.
findAll
({
include
:
[{
...
...
@@ -2666,7 +2666,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this
.
User
.
create
(),
this
.
Project
.
create
()
]).
then
(([
user
,
project
])
=>
{
return
user
.
addProject
(
project
,
{
through
:
{
status
:
'active'
,
data
:
42
}
}).
return
(
user
);
return
user
.
addProject
(
project
,
{
through
:
{
status
:
'active'
,
data
:
42
}
}).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
user
.
getProjects
({
joinTableAttributes
:
[
'status'
]
});
}).
then
(
projects
=>
{
...
...
@@ -2867,7 +2867,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
})
]);
}).
then
(([
worker
,
tasks
])
=>
{
return
worker
.
setTasks
(
tasks
).
return
(
[
worker
,
tasks
]);
return
worker
.
setTasks
(
tasks
).
then
(()
=>
[
worker
,
tasks
]);
}).
then
(([
worker
,
tasks
])
=>
{
return
worker
.
setTasks
(
tasks
);
});
...
...
test/integration/associations/has-many.test.js
View file @
04573fd
...
...
@@ -48,7 +48,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
return
Promise
.
join
(
user
.
get
(
'Tasks'
)[
0
].
createSubtask
({
title
:
'Make a startup'
,
active
:
false
}),
user
.
get
(
'Tasks'
)[
0
].
createSubtask
({
title
:
'Engage rock stars'
,
active
:
true
})
).
return
(
user
);
).
then
(()
=>
user
);
}).
then
(
user
=>
{
return
expect
(
user
.
countTasks
({
attributes
:
[
Task
.
primaryKeyField
,
'title'
],
...
...
@@ -943,7 +943,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
Article
.
create
({
title
:
'foo'
});
}).
then
(
article
=>
{
return
article
.
createLabel
({
text
:
'bar'
}).
return
(
article
);
return
article
.
createLabel
({
text
:
'bar'
}).
then
(()
=>
article
);
}).
then
(
article
=>
{
return
Label
.
findAll
({
where
:
{
ArticleId
:
article
.
id
}
});
}).
then
(
labels
=>
{
...
...
@@ -1027,7 +1027,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
text
:
'yolo'
},
{
fields
:
[
'text'
]
}).
return
(
article
);
}).
then
(()
=>
article
);
}).
then
(
article
=>
{
return
article
.
getLabels
();
}).
then
(
labels
=>
{
...
...
@@ -1265,7 +1265,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task
.
create
({
title
:
'task'
})
]);
}).
then
(([
user
,
task
])
=>
{
return
user
.
setTasks
([
task
]).
return
(
user
);
return
user
.
setTasks
([
task
]).
then
(()
=>
user
);
}).
then
(
user
=>
{
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
...
...
@@ -1321,7 +1321,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task
.
create
({
title
:
'task'
})
]);
}).
then
(([
user
,
task
])
=>
{
return
user
.
setTasks
([
task
]).
return
(
user
);
return
user
.
setTasks
([
task
]).
then
(()
=>
user
);
}).
then
(
user
=>
{
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
...
...
test/integration/hooks/associations.test.js
View file @
04573fd
...
...
@@ -866,7 +866,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
return
Sequelize
.
Promise
.
all
([
task
.
addMiniTask
(
minitask
),
project
.
addTask
(
task
)
]).
return
(
project
);
]).
then
(()
=>
project
);
}).
then
(
project
=>
{
return
project
.
destroy
();
}).
then
(()
=>
{
...
...
@@ -921,7 +921,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
return
Sequelize
.
Promise
.
all
([
task
.
addMiniTask
(
minitask
),
project
.
addTask
(
task
)
]).
return
(
project
);
]).
then
(()
=>
project
);
}).
then
(
project
=>
{
return
expect
(
project
.
destroy
()).
to
.
eventually
.
be
.
rejectedWith
(
CustomErrorText
).
then
(()
=>
{
expect
(
beforeProject
).
to
.
be
.
true
;
...
...
test/integration/include.test.js
View file @
04573fd
...
...
@@ -273,7 +273,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return
Promise
.
join
(
props
.
task
.
setUser
(
props
.
user
),
props
.
user
.
setGroup
(
props
.
group
)
).
return
(
props
);
).
then
(()
=>
props
);
}).
then
(
props
=>
{
return
Task
.
findOne
({
where
:
{
...
...
test/integration/instance/reload.test.js
View file @
04573fd
...
...
@@ -244,7 +244,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
include
:
[
Shoe
]
}).
then
(
lePlayer
=>
{
expect
(
lePlayer
.
Shoe
).
not
.
to
.
be
.
null
;
return
lePlayer
.
Shoe
.
destroy
().
return
(
lePlayer
);
return
lePlayer
.
Shoe
.
destroy
().
then
(()
=>
lePlayer
);
}).
then
(
lePlayer
=>
{
return
lePlayer
.
reload
();
}).
then
(
lePlayer
=>
{
...
...
@@ -277,7 +277,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
expect
(
leTeam
.
Players
).
not
.
to
.
be
.
empty
;
return
leTeam
.
Players
[
1
].
destroy
().
then
(()
=>
{
return
leTeam
.
Players
[
0
].
destroy
();
}).
return
(
leTeam
);
}).
then
(()
=>
leTeam
);
}).
then
(
leTeam
=>
{
return
leTeam
.
reload
();
}).
then
(
leTeam
=>
{
...
...
@@ -309,7 +309,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
include
:
[
Player
]
}).
then
(
leTeam
=>
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
2
);
return
leTeam
.
Players
[
0
].
destroy
().
return
(
leTeam
);
return
leTeam
.
Players
[
0
].
destroy
().
then
(()
=>
leTeam
);
}).
then
(
leTeam
=>
{
return
leTeam
.
reload
();
}).
then
(
leTeam
=>
{
...
...
test/support.js
View file @
04573fd
...
...
@@ -44,7 +44,7 @@ const Support = {
const
options
=
Object
.
assign
({},
sequelize
.
options
,
{
storage
:
p
}),
_sequelize
=
new
Sequelize
(
sequelize
.
config
.
database
,
null
,
null
,
options
);
return
_sequelize
.
sync
({
force
:
true
}).
return
(
_sequelize
);
return
_sequelize
.
sync
({
force
:
true
}).
then
(()
=>
_sequelize
);
}
return
Sequelize
.
Promise
.
resolve
(
sequelize
);
},
...
...
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