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 66ac75f6
authored
Mar 02, 2016
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using rejectOnEmpty option name, changelog
1 parent
8ff99286
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
24 deletions
changelog.md
lib/errors.js
lib/model.js
lib/sequelize.js
test/integration/model/find.test.js
test/integration/model/findAll.test.js
changelog.md
View file @
66ac75f
# Future
# Future
-
[
ADDED
]
rejectOnEmpty mode
[
#272
](
https://github.com/sequelize/sequelize/issues/272
)
[
#5480
]
(https://github.com/sequelize/sequelize/issues/5480)
-
[
ADDED
]
`beforeCount`
hook
[
#5209
](
https://github.com/sequelize/sequelize/pull/5209
)
-
[
ADDED
]
`beforeCount`
hook
[
#5209
](
https://github.com/sequelize/sequelize/pull/5209
)
-
[
ADDED
]
`validationFailed`
hook
[
#1626
](
https://github.com/sequelize/sequelize/issues/1626
)
-
[
ADDED
]
`validationFailed`
hook
[
#1626
](
https://github.com/sequelize/sequelize/issues/1626
)
-
[
FIXED
]
Mark index as
`unique: true`
when
`type: 'UNIQUE'`
. Fixes
[
#5351
](
https://github.com/sequelize/sequelize/issues/5351
)
-
[
FIXED
]
Mark index as
`unique: true`
when
`type: 'UNIQUE'`
. Fixes
[
#5351
](
https://github.com/sequelize/sequelize/issues/5351
)
...
...
lib/errors.js
View file @
66ac75f
...
@@ -301,7 +301,7 @@ error.InstanceError = function (message) {
...
@@ -301,7 +301,7 @@ error.InstanceError = function (message) {
util
.
inherits
(
error
.
InstanceError
,
error
.
BaseError
);
util
.
inherits
(
error
.
InstanceError
,
error
.
BaseError
);
/**
/**
* Thrown when a record was not found, Usually used with
kenophobic
mode (see message for details)
* Thrown when a record was not found, Usually used with
rejectOnEmpty
mode (see message for details)
* @extends BaseError
* @extends BaseError
* @constructor
* @constructor
*/
*/
...
...
lib/model.js
View file @
66ac75f
...
@@ -35,7 +35,7 @@ var Model = function(name, attributes, options) {
...
@@ -35,7 +35,7 @@ var Model = function(name, attributes, options) {
underscored
:
false
,
underscored
:
false
,
underscoredAll
:
false
,
underscoredAll
:
false
,
paranoid
:
false
,
paranoid
:
false
,
kenophobic
:
false
,
rejectOnEmpty
:
false
,
whereCollection
:
null
,
whereCollection
:
null
,
schema
:
null
,
schema
:
null
,
schemaDelimiter
:
''
,
schemaDelimiter
:
''
,
...
@@ -1335,7 +1335,7 @@ Model.prototype.all = function(options) {
...
@@ -1335,7 +1335,7 @@ Model.prototype.all = function(options) {
* @param {Object} [options.having]
* @param {Object} [options.having]
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {Boolean} [options.benchmark=false] Print query execution time in milliseconds when logging SQL.
* @param {Boolean} [options.benchmark=false] Print query execution time in milliseconds when logging SQL.
* @param {Boolean|Error Instance} [options.
kenophobic=false] Throws error when no record i
s found
* @param {Boolean|Error Instance} [options.
rejectOnEmpty=false] Throws an error when no record
s found
*
*
* @see {Sequelize#query}
* @see {Sequelize#query}
* @return {Promise<Array<Instance>>}
* @return {Promise<Array<Instance>>}
...
@@ -1356,10 +1356,10 @@ Model.prototype.findAll = function(options) {
...
@@ -1356,10 +1356,10 @@ Model.prototype.findAll = function(options) {
tableNames
[
this
.
getTableName
(
options
)]
=
true
;
tableNames
[
this
.
getTableName
(
options
)]
=
true
;
options
=
optClone
(
options
);
options
=
optClone
(
options
);
_
.
defaults
(
options
,
{
hooks
:
true
,
kenophobic
:
false
});
_
.
defaults
(
options
,
{
hooks
:
true
,
rejectOnEmpty
:
this
.
options
.
rejectOnEmpty
});
//set kenophobic
option from model config
//set rejectOnEmpty
option from model config
options
.
kenophobic
=
options
.
kenophobic
||
this
.
options
.
kenophobic
;
options
.
rejectOnEmpty
=
options
.
rejectOnEmpty
||
this
.
options
.
rejectOnEmpty
;
return
Promise
.
bind
(
this
).
then
(
function
()
{
return
Promise
.
bind
(
this
).
then
(
function
()
{
conformOptions
(
options
,
this
);
conformOptions
(
options
,
this
);
...
@@ -1411,12 +1411,12 @@ Model.prototype.findAll = function(options) {
...
@@ -1411,12 +1411,12 @@ Model.prototype.findAll = function(options) {
}
}
}).
then
(
function
(
results
)
{
}).
then
(
function
(
results
)
{
//
kenophobic
mode
//
rejectOnEmpty
mode
if
(
_
.
isEmpty
(
results
)
&&
options
.
kenophobic
)
{
if
(
_
.
isEmpty
(
results
)
&&
options
.
rejectOnEmpty
)
{
if
(
typeof
options
.
kenophobic
===
'function'
)
{
if
(
typeof
options
.
rejectOnEmpty
===
'function'
)
{
throw
new
options
.
kenophobic
();
throw
new
options
.
rejectOnEmpty
();
}
else
if
(
typeof
options
.
kenophobic
===
'object'
)
{
}
else
if
(
typeof
options
.
rejectOnEmpty
===
'object'
)
{
throw
options
.
kenophobic
;
throw
options
.
rejectOnEmpty
;
}
else
{
}
else
{
throw
new
sequelizeErrors
.
EmptyResultError
();
throw
new
sequelizeErrors
.
EmptyResultError
();
}
}
...
@@ -1535,7 +1535,7 @@ Model.prototype.findOne = function(options) {
...
@@ -1535,7 +1535,7 @@ Model.prototype.findOne = function(options) {
// Bypass a possible overloaded findAll.
// Bypass a possible overloaded findAll.
return
Model
.
prototype
.
findAll
.
call
(
this
,
_
.
defaults
(
options
,
{
return
Model
.
prototype
.
findAll
.
call
(
this
,
_
.
defaults
(
options
,
{
plain
:
true
,
plain
:
true
,
kenophobic
:
false
rejectOnEmpty
:
false
}));
}));
};
};
Model
.
prototype
.
find
=
Model
.
prototype
.
findOne
;
Model
.
prototype
.
find
=
Model
.
prototype
.
findOne
;
...
...
lib/sequelize.js
View file @
66ac75f
...
@@ -442,7 +442,7 @@ Sequelize.prototype.InstanceError = Sequelize.InstanceError =
...
@@ -442,7 +442,7 @@ Sequelize.prototype.InstanceError = Sequelize.InstanceError =
sequelizeErrors
.
InstanceError
;
sequelizeErrors
.
InstanceError
;
/**
/**
* Thrown when a record was not found, Usually used with
kenophobic
mode (see message for details)
* Thrown when a record was not found, Usually used with
rejectOnEmpty
mode (see message for details)
* @see {Errors#RecordNotFoundError}
* @see {Errors#RecordNotFoundError}
*/
*/
Sequelize
.
prototype
.
EmptyResultError
=
Sequelize
.
EmptyResultError
=
Sequelize
.
prototype
.
EmptyResultError
=
Sequelize
.
EmptyResultError
=
...
...
test/integration/model/find.test.js
View file @
66ac75f
...
@@ -936,19 +936,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -936,19 +936,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
describe
(
'
kenophobic
mode'
,
function
()
{
describe
(
'
rejectOnEmpty
mode'
,
function
()
{
it
(
'throws error when record not found by findOne'
,
function
()
{
it
(
'throws error when record not found by findOne'
,
function
()
{
return
expect
(
this
.
User
.
findOne
({
return
expect
(
this
.
User
.
findOne
({
where
:
{
where
:
{
username
:
'ath-kantam-pradakshnami'
username
:
'ath-kantam-pradakshnami'
},
},
kenophobic
:
true
rejectOnEmpty
:
true
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
EmptyResultError
);
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
EmptyResultError
);
});
});
it
(
'throws error when record not found by findById'
,
function
()
{
it
(
'throws error when record not found by findById'
,
function
()
{
return
expect
(
this
.
User
.
findById
(
4732322332323333232344334354234
,
{
return
expect
(
this
.
User
.
findById
(
4732322332323333232344334354234
,
{
kenophobic
:
true
rejectOnEmpty
:
true
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
EmptyResultError
);
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
EmptyResultError
);
});
});
...
@@ -957,7 +957,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -957,7 +957,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
where
:
{
where
:
{
username
:
'some-username-that-is-not-used-anywhere'
username
:
'some-username-that-is-not-used-anywhere'
},
},
kenophobic
:
true
rejectOnEmpty
:
true
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
EmptyResultError
);
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
EmptyResultError
);
});
});
...
@@ -965,7 +965,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -965,7 +965,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var
Model
=
current
.
define
(
'Test'
,
{
var
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
username
:
Sequelize
.
STRING
(
100
)
},{
},{
kenophobic
:
true
rejectOnEmpty
:
true
});
});
return
Model
.
sync
({
force
:
true
})
return
Model
.
sync
({
force
:
true
})
...
...
test/integration/model/findAll.test.js
View file @
66ac75f
...
@@ -1390,12 +1390,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1390,12 +1390,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
describe
(
'
kenophobic
mode'
,
function
()
{
describe
(
'
rejectOnEmpty
mode'
,
function
()
{
it
(
'works from model options'
,
function
()
{
it
(
'works from model options'
,
function
()
{
var
Model
=
current
.
define
(
'Test'
,
{
var
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
username
:
Sequelize
.
STRING
(
100
)
},{
},{
kenophobic
:
true
rejectOnEmpty
:
true
});
});
return
Model
.
sync
({
force
:
true
})
return
Model
.
sync
({
force
:
true
})
...
@@ -1413,7 +1413,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1413,7 +1413,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var
Model
=
current
.
define
(
'Test'
,
{
var
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
username
:
Sequelize
.
STRING
(
100
)
},{
},{
kenophobic
:
new
Sequelize
.
ConnectionError
(
'Some Error'
)
//using custom error instance
rejectOnEmpty
:
new
Sequelize
.
ConnectionError
(
'Some Error'
)
//using custom error instance
});
});
return
Model
.
sync
({
force
:
true
})
return
Model
.
sync
({
force
:
true
})
...
@@ -1431,7 +1431,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1431,7 +1431,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var
Model
=
current
.
define
(
'Test'
,
{
var
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
username
:
Sequelize
.
STRING
(
100
)
},{
},{
kenophobic
:
Sequelize
.
ConnectionError
//using custom error instance
rejectOnEmpty
:
Sequelize
.
ConnectionError
//using custom error instance
});
});
return
Model
.
sync
({
force
:
true
})
return
Model
.
sync
({
force
:
true
})
...
@@ -1443,7 +1443,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1443,7 +1443,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ConnectionError
);
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ConnectionError
);
});
});
});
});
});
});
});
});
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