1- [ ![ Build Status] ( https://travis-ci.org/Vincit/db-errors.svg?branch=master )] ( https://travis-ci.org/Vincit/db-errors )
2-
31# Unified error API for node.js SQL DB drivers
42
53This project is an attempt to create a unified API for node.js SQL DB driver errors. Each driver
@@ -8,7 +6,7 @@ pass these errors through. It's usually very difficult to reason with these erro
86library wraps those errors to error classes that are the same for all drivers. The wrapped
97error classes also expose useful information about the errors.
108
11- __ NOTE __ : Only MySQL, Sqlite3, MSSQL and PostgreSQL are officially supported (tested).
9+ ** NOTE ** : Only MySQL, Sqlite3, MSSQL and PostgreSQL are officially supported (tested).
1210
1311# Contributions and suggestions are most welcome
1412
@@ -20,12 +18,7 @@ If you have an idea for an error we should handle, please open an issue and we'l
2018## Usage
2119
2220``` js
23- const {
24- wrapError ,
25- DBError ,
26- UniqueViolationError ,
27- NotNullViolationError
28- } = require (' db-errors' );
21+ const { wrapError , DBError , UniqueViolationError , NotNullViolationError } = require (' db-errors' );
2922
3023function errorHandler (err ) {
3124 // wrapError function takes any error and returns a DBError subclass instance if
@@ -34,7 +27,9 @@ function errorHandler(err) {
3427 err = wrapError (err);
3528
3629 if (err instanceof UniqueViolationError) {
37- console .log (` Unique constraint ${ err .constraint } failed for table ${ err .table } and columns ${ err .columns } ` );
30+ console .log (
31+ ` Unique constraint ${ err .constraint } failed for table ${ err .table } and columns ${ err .columns } `
32+ );
3833 } else if (err instanceof NotNullViolationError) {
3934 console .log (` Not null constraint failed for table ${ err .table } and column ${ err .column } ` );
4035 } else if (err instanceof DBError) {
@@ -56,7 +51,7 @@ function errorHandler(err) {
5651``` ts
5752class DBError extends Error {
5853 // The error thrown by the database client.
59- nativeError: Error
54+ nativeError: Error ;
6055}
6156```
6257
@@ -85,17 +80,17 @@ class UniqueViolationError extends ConstraintViolationError {
8580 // The columns that failed.
8681 //
8782 // Available for: postgres, sqlite
88- columns: string []
83+ columns: string [];
8984
9085 // The table that has the columns.
9186 //
9287 // Available for: postgres, sqlite
93- table: string
88+ table: string ;
9489
9590 // The constraint that was violated.
9691 //
9792 // Available for: postgres, mysql
98- constraint: string
93+ constraint: string ;
9994}
10095```
10196
@@ -109,12 +104,12 @@ class NotNullViolationError extends ConstraintViolationError {
109104 // The column that failed.
110105 //
111106 // Available for: postgres, sqlite, mysql
112- column: string
107+ column: string ;
113108
114109 // The table that has the columns.
115110 //
116111 // Available for: postgres, sqlite
117- table: string
112+ table: string ;
118113}
119114```
120115
@@ -128,12 +123,12 @@ class ForeignKeyViolationError extends ConstraintViolationError {
128123 // The table that has the foreign key.
129124 //
130125 // Available for: postgres, mysql
131- table: string
126+ table: string ;
132127
133128 // The constraint that was violated.
134129 //
135130 // Available for: postgres, mysql
136- constraint: string
131+ constraint: string ;
137132}
138133```
139134
@@ -148,12 +143,12 @@ class CheckViolationError extends ConstraintViolationError {
148143 // The table that has the check constraint.
149144 //
150145 // Available for: postgres
151- table: string
146+ table: string ;
152147
153148 // The constraint that was violated.
154149 //
155150 // Available for: postgres
156- constraint: string
151+ constraint: string ;
157152}
158153```
159154
@@ -175,7 +170,6 @@ class DataError extends DBError {
175170<br >
176171<br >
177172
178-
179173## Development setup
180174
181175Run the following commands in the repo root:
0 commit comments