Skip to content

Commit 2cfd284

Browse files
committed
migrate tests to github actions
1 parent 6ed1975 commit 2cfd284

File tree

58 files changed

+8184
-3623
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+8184
-3623
lines changed

.github/workflows/test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
run-tests:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [12.x, 14.x, 16.x]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run docker compose
29+
run: docker-compose -f docker-compose.yml -f docker-compose-ci.yml up -d
30+
31+
- name: Wait until docker compose is up
32+
run: sleep 30
33+
34+
- name: Run tests
35+
run: npm run test:ci

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"bracketSpacing": true,
5+
"semi": true
6+
}

.travis.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

README.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
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

53
This 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
86
library wraps those errors to error classes that are the same for all drivers. The wrapped
97
error 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

3023
function 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
5752
class 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

181175
Run the following commands in the repo root:

docker-compose-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
mssql:
3+
image: 'mcr.microsoft.com/mssql/server'
4+
environment:
5+
ACCEPT_EULA: 'Y'
6+
SA_PASSWORD: eioC9vvCZzQSy4S9g37i
7+
ports:
8+
- '1433:1433'

docker-compose.yml

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
version: "3"
1+
version: '3'
22
services:
3-
mssql:
4-
image: "microsoft/mssql-server-linux:2017-CU12"
5-
environment:
6-
- ACCEPT_EULA=Y
7-
- SA_PASSWORD=eioC9vvCZzQSy4S9g37i
8-
ports:
9-
- "1433:1433"
103
mysql:
11-
image: "mysql:5"
4+
image: 'mysql/mysql-server'
125
environment:
13-
- MYSQL_DATABASE=db_errors_test
14-
- MYSQL_USER=db_errors
15-
- MYSQL_ROOT_PASSWORD=root
16-
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
6+
MYSQL_ROOT_PASSWORD: root
7+
MYSQL_DATABASE: db_errors_test
178
ports:
18-
- "3306:3306"
9+
- '3307:3306'
10+
volumes:
11+
- ./testUtils/sql/mysqlInit.sql:/data/application/init.sql
12+
command: --init-file /data/application/init.sql
1913
postgres:
20-
image: "postgres:10"
14+
image: 'postgres'
2115
environment:
22-
- POSTGRES_DB=db_errors_test
23-
- POSTGRES_USER=db_errors
16+
POSTGRES_DB: db_errors_test
17+
POSTGRES_USER: db_errors
18+
POSTGRES_HOST_AUTH_METHOD: trust
2419
ports:
25-
- "5432:5432"
20+
- '5433:5432'

index.d.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
declare namespace DbTypes {
2+
type DBErrorClient = 'postgres' | 'mysql' | 'mssql' | 'sqlite';
3+
4+
interface DBErrorArgs {
5+
nativeError: Error;
6+
client: DBErrorClient;
7+
}
28

39
class DBError extends Error {
10+
constructor(args: DBErrorArgs);
11+
412
name: string;
513
nativeError: Error;
14+
client: DBErrorClient;
15+
}
16+
17+
interface CheckViolationErrorArgs extends DBErrorArgs {
18+
table: string;
19+
constraint: string;
620
}
721

822
class CheckViolationError extends DBError {
23+
constructor(args: CheckViolationErrorArgs);
24+
925
table: string;
1026
constraint: string;
1127
}
@@ -14,27 +30,53 @@ declare namespace DbTypes {
1430

1531
class DataError extends DBError {}
1632

33+
interface ForeignKeyViolationErrorArgs extends DBErrorArgs {
34+
table: string;
35+
constraint: string;
36+
schema?: string;
37+
}
38+
1739
class ForeignKeyViolationError extends ConstraintViolationError {
40+
constructor(args: ForeignKeyViolationErrorArgs);
41+
1842
table: string;
1943
constraint: string;
2044
schema?: string;
2145
}
2246

47+
interface NotNullViolationErrorArgs extends DBErrorArgs {
48+
table: string;
49+
column: string;
50+
database?: string;
51+
schema?: string;
52+
}
53+
2354
class NotNullViolationError extends ConstraintViolationError {
55+
constructor(args: NotNullViolationErrorArgs);
56+
2457
table: string;
2558
column: string;
2659
database?: string;
2760
schema?: string;
2861
}
2962

63+
interface UniqueViolationErrorArgs extends DBErrorArgs {
64+
table: string;
65+
columns: string[];
66+
constraint: string;
67+
schema?: string;
68+
}
69+
3070
class UniqueViolationError extends ConstraintViolationError {
71+
constructor(args: UniqueViolationErrorArgs);
72+
3173
table: string;
3274
columns: string[];
3375
constraint: string;
3476
schema?: string;
3577
}
3678

37-
function wrapError(err: Error): DBError
79+
function wrapError(err: Error): DBError;
3880

3981
export {
4082
wrapError,
@@ -45,7 +87,7 @@ declare namespace DbTypes {
4587
ForeignKeyViolationError,
4688
NotNullViolationError,
4789
UniqueViolationError,
48-
}
90+
};
4991
}
5092

51-
export = DbTypes
93+
export = DbTypes;

lib/dbErrors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function parse(node, err, parentResult) {
3232

3333
const result = {
3434
node,
35-
args: Object.assign({}, parentResult && parentResult.args, args)
35+
args: Object.assign({}, parentResult && parentResult.args, args),
3636
};
3737

3838
for (let i = 0; i < node.subclassParsers.length; ++i) {
@@ -55,5 +55,5 @@ module.exports = {
5555
ForeignKeyViolationError,
5656
ConstraintViolationError,
5757
CheckViolationError,
58-
DataError
59-
};
58+
DataError,
59+
};

lib/errorCodes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ module.exports = {
88
postgres,
99
mysql,
1010
mssql,
11-
};
11+
};

0 commit comments

Comments
 (0)