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 f4a46dc1
authored
Apr 16, 2019
by
Mirko Jotic
Committed by
Sushant
Apr 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(typings): add OptimisticLockError type (#10777)
1 parent
380738b8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
types/lib/errors.d.ts
types/test/errors.ts
types/lib/errors.d.ts
View file @
f4a46dc
...
@@ -130,6 +130,13 @@ export class ExclusionConstraintError extends DatabaseError {
...
@@ -130,6 +130,13 @@ export class ExclusionConstraintError extends DatabaseError {
}
}
/**
/**
* Thrown when attempting to update a stale model instance
*/
export
class
OptimisticLockError
extends
BaseError
{
constructor
(
options
:
{
message
?:
string
,
modelName
?:
string
,
values
?:
{
[
key
:
string
]:
any
},
where
?:
{
[
key
:
string
]:
any
}
});
}
/**
* A base class for all connection related errors.
* A base class for all connection related errors.
*/
*/
export
class
ConnectionError
extends
BaseError
{
export
class
ConnectionError
extends
BaseError
{
...
...
types/test/errors.ts
View file @
f4a46dc
// Error === BaseError
// Error === BaseError
import
{
BaseError
,
EmptyResultError
,
Error
,
UniqueConstraintError
}
from
'sequelize'
;
import
{
BaseError
,
EmptyResultError
,
Error
,
UniqueConstraintError
}
from
'sequelize'
;
import
{
User
}
from
'./models/User'
;
import
{
User
}
from
'./models/User'
;
import
{
OptimisticLockError
}
from
'../lib/errors'
;
async
function
test
()
{
async
function
test
()
{
try
{
try
{
...
@@ -23,4 +24,16 @@ async function test() {
...
@@ -23,4 +24,16 @@ async function test() {
console
.
error
(
'should return emptyresulterror'
);
console
.
error
(
'should return emptyresulterror'
);
}
}
}
}
try
{
const
user
:
User
|
null
=
await
User
.
findByPk
(
1
);
if
(
user
!=
null
)
{
user
.
username
=
'foo'
;
user
.
save
();
}
}
catch
(
e
)
{
if
(
!
(
e
instanceof
OptimisticLockError
))
{
console
.
log
(
'should return OptimisticLockError'
);
}
}
}
}
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