From e5860485cce39be27a321377a6f3b04b1d89d284 Mon Sep 17 00:00:00 2001 From: pueue Date: Thu, 29 Jun 2017 16:52:13 +0900 Subject: [PATCH] Add EmptyResultError --- types/sequelize/index.d.ts | 15 +++++++++++++++ types/sequelize/sequelize-tests.ts | 2 ++ 2 files changed, 17 insertions(+) diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index 86ecb00809..97047aada6 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -2185,6 +2185,15 @@ declare namespace sequelize { } + interface EmptyResultError extends BaseError { + + /** + * Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details) + */ + new (parent: Error): EmptyResultError; + + } + /** * Sequelize provides a host of custom error classes, to allow you to do easier debugging. All of these errors * are exposed on the sequelize object and the sequelize constructor. All sequelize errors inherit from the @@ -2206,6 +2215,7 @@ declare namespace sequelize { HostNotReachableError: HostNotReachableError; InvalidConnectionError: InvalidConnectionError; ConnectionTimedOutError: ConnectionTimedOutError; + EmptyResultError: EmptyResultError; } // @@ -3263,6 +3273,11 @@ declare namespace sequelize { * Prevents a subquery on the main table when using include */ subQuery?: boolean; + + /** + * Throw EmptyResultError if a record is not found + */ + rejectOnEmpty?: boolean; } /** diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index d786dfc4a2..02249377a9 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -629,6 +629,7 @@ new s.HostNotFoundError( new Error( 'original connection error message' ) ); new s.HostNotReachableError( new Error( 'original connection error message' ) ); new s.InvalidConnectionError( new Error( 'original connection error message' ) ); new s.ConnectionTimedOutError( new Error( 'original connection error message' ) ); +new s.EmptyResultError(); const uniqueConstraintError: Sequelize.ValidationError = new s.UniqueConstraintError({}); @@ -914,6 +915,7 @@ User.findAll( { attributes: [s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER' User.findAll( { attributes: [[s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER'), 'count']] }); User.findAll( { where : s.fn('count', [0, 10]) } ); User.findAll( { subQuery: false, include : [User], order : [[User, User, 'numYears', 'c']] } ); +User.findAll( { rejectOnEmpty: true }); User.findById( 'a string' );