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 3444f189
authored
May 27, 2014
by
Overlook Motel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import Promise
1 parent
41fc53bf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
lib/instance.js
lib/model.js
lib/instance.js
View file @
3444f18
...
@@ -4,6 +4,7 @@ var Utils = require('./utils')
...
@@ -4,6 +4,7 @@ var Utils = require('./utils')
,
Mixin
=
require
(
'./associations/mixin'
)
,
Mixin
=
require
(
'./associations/mixin'
)
,
InstanceValidator
=
require
(
'./instance-validator'
)
,
InstanceValidator
=
require
(
'./instance-validator'
)
,
DataTypes
=
require
(
'./data-types'
)
,
DataTypes
=
require
(
'./data-types'
)
,
Promise
=
require
(
"./promise"
)
,
_
=
require
(
'lodash'
)
,
_
=
require
(
'lodash'
)
,
defaultsOptions
=
{
raw
:
true
};
,
defaultsOptions
=
{
raw
:
true
};
...
...
lib/model.js
View file @
3444f18
...
@@ -8,6 +8,7 @@ var Utils = require('./utils')
...
@@ -8,6 +8,7 @@ var Utils = require('./utils')
,
sql
=
require
(
'sql'
)
,
sql
=
require
(
'sql'
)
,
SqlString
=
require
(
'./sql-string'
)
,
SqlString
=
require
(
'./sql-string'
)
,
Transaction
=
require
(
'./transaction'
)
,
Transaction
=
require
(
'./transaction'
)
,
Promise
=
require
(
"./promise"
)
,
QueryTypes
=
require
(
'./query-types'
);
,
QueryTypes
=
require
(
'./query-types'
);
module
.
exports
=
(
function
()
{
module
.
exports
=
(
function
()
{
...
@@ -708,7 +709,7 @@ module.exports = (function() {
...
@@ -708,7 +709,7 @@ module.exports = (function() {
// no options defined?
// no options defined?
// return an emitter which emits null
// return an emitter which emits null
if
([
null
,
undefined
].
indexOf
(
options
)
!==
-
1
)
{
if
([
null
,
undefined
].
indexOf
(
options
)
!==
-
1
)
{
return
Utils
.
Promise
.
resolve
(
null
);
return
Promise
.
resolve
(
null
);
}
}
var
primaryKeys
=
this
.
primaryKeys
var
primaryKeys
=
this
.
primaryKeys
...
@@ -1045,11 +1046,11 @@ module.exports = (function() {
...
@@ -1045,11 +1046,11 @@ module.exports = (function() {
var
build
=
self
.
build
(
params
);
var
build
=
self
.
build
(
params
);
return
build
.
hookValidate
({
skip
:
Object
.
keys
(
params
)}).
then
(
function
()
{
return
build
.
hookValidate
({
skip
:
Object
.
keys
(
params
)}).
then
(
function
()
{
return
Utils
.
Promise
.
resolve
([
build
,
true
]);
return
Promise
.
resolve
([
build
,
true
]);
});
});
}
}
return
Utils
.
Promise
.
resolve
([
instance
,
false
]);
return
Promise
.
resolve
([
instance
,
false
]);
});
});
};
};
...
@@ -1089,11 +1090,11 @@ module.exports = (function() {
...
@@ -1089,11 +1090,11 @@ module.exports = (function() {
}
}
return
self
.
create
(
values
,
options
).
then
(
function
(
instance
)
{
return
self
.
create
(
values
,
options
).
then
(
function
(
instance
)
{
return
Utils
.
Promise
.
resolve
([
instance
,
true
]);
return
Promise
.
resolve
([
instance
,
true
]);
});
});
}
}
return
Utils
.
Promise
.
resolve
([
instance
,
false
]);
return
Promise
.
resolve
([
instance
,
false
]);
});
});
};
};
...
@@ -1118,7 +1119,7 @@ module.exports = (function() {
...
@@ -1118,7 +1119,7 @@ module.exports = (function() {
Utils
.
validateParameter
(
options
,
'undefined'
,
{
deprecated
:
Object
,
optional
:
true
,
index
:
3
,
method
:
'Model#bulkCreate'
});
Utils
.
validateParameter
(
options
,
'undefined'
,
{
deprecated
:
Object
,
optional
:
true
,
index
:
3
,
method
:
'Model#bulkCreate'
});
if
(
!
records
.
length
)
{
if
(
!
records
.
length
)
{
return
new
Utils
.
Promise
(
function
(
resolve
)
{
return
new
Promise
(
function
(
resolve
)
{
resolve
([]);
resolve
([]);
});
});
}
}
...
@@ -1137,7 +1138,7 @@ module.exports = (function() {
...
@@ -1137,7 +1138,7 @@ module.exports = (function() {
}
}
if
(
this
.
sequelize
.
options
.
dialect
===
'postgres'
&&
options
.
ignoreDuplicates
)
{
if
(
this
.
sequelize
.
options
.
dialect
===
'postgres'
&&
options
.
ignoreDuplicates
)
{
return
Utils
.
Promise
.
reject
(
new
Error
(
'Postgres does not support the \'ignoreDuplicates\' option.'
));
return
Promise
.
reject
(
new
Error
(
'Postgres does not support the \'ignoreDuplicates\' option.'
));
}
}
var
self
=
this
var
self
=
this
...
@@ -1157,7 +1158,7 @@ module.exports = (function() {
...
@@ -1157,7 +1158,7 @@ module.exports = (function() {
var
runAfterCreate
=
function
()
{
var
runAfterCreate
=
function
()
{
return
self
.
runHooks
(
'afterBulkCreate'
,
daos
,
options
.
fields
).
spread
(
function
(
newRecords
)
{
return
self
.
runHooks
(
'afterBulkCreate'
,
daos
,
options
.
fields
).
spread
(
function
(
newRecords
)
{
return
new
self
.
sequelize
.
Promise
.
resolve
(
newRecords
||
daos
);
return
new
Promise
.
resolve
(
newRecords
||
daos
);
});
});
};
};
...
@@ -1213,10 +1214,10 @@ module.exports = (function() {
...
@@ -1213,10 +1214,10 @@ module.exports = (function() {
daoPromises
.
push
(
runHook
(
dao
));
daoPromises
.
push
(
runHook
(
dao
));
});
});
return
self
.
sequelize
.
Promise
.
all
(
daoPromises
).
then
(
function
()
{
return
Promise
.
all
(
daoPromises
).
then
(
function
()
{
if
(
errors
.
length
)
{
if
(
errors
.
length
)
{
// Validation or hooks failed
// Validation or hooks failed
return
self
.
sequelize
.
Promise
.
reject
(
errors
);
return
Promise
.
reject
(
errors
);
}
else
if
(
records
.
length
)
{
}
else
if
(
records
.
length
)
{
// Map field names
// Map field names
records
.
forEach
(
function
(
values
)
{
records
.
forEach
(
function
(
values
)
{
...
...
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