Skip to content

Commit

Permalink
add mysql testing
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Oct 11, 2024
1 parent 5ad34d0 commit 6f9253f
Show file tree
Hide file tree
Showing 9 changed files with 452 additions and 70 deletions.
34 changes: 33 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: npm test

test_postgre:
name: 'Postgres Connection Test'
name: 'Postgres Connection'
runs-on: ubuntu-latest
needs: build

Expand All @@ -49,9 +49,41 @@ jobs:

- name: Run tests
env:
CONNECTION_TYPE: postgres
POSTGRES_HOST: localhost
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 123456
POSTGRES_PORT: 5432
run: npm run test:connection

test_mysql:
name: 'MySQL Connection'
runs-on: ubuntu-latest
needs: build

services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: testdb
MYSQL_ROOT_PASSWORD: 123456
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v4

- name: Install modules
run: npm install

- name: Run tests
env:
CONNECTION_TYPE: mysql
MYSQL_HOST: localhost
MYSQL_DB: testdb
MYSQL_USER: root
MYSQL_PASSWORD: 123456
MYSQL_PORT: 3306
run: npm run test:connection
125 changes: 123 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.4",
"mysql2": "^3.11.3",
"pg": "^8.13.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.3",
Expand Down
8 changes: 5 additions & 3 deletions src/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type OperationResponse = {
error: Error | null;
};

export interface QueryResult {
data: Record<string, unknown>[];
export interface QueryResult<T = Record<string, unknown>> {
data: T[];
error: Error | null;
query: string;
}
Expand All @@ -24,7 +24,9 @@ export interface Connection {
disconnect: () => Promise<any>;

// Raw query execution method that can be used to execute any query.
query: (query: Query) => Promise<QueryResult>;
query: <T = Record<string, unknown>>(
query: Query
) => Promise<QueryResult<T>>;

// Retrieve metadata about the database, useful for introspection.
fetchDatabaseSchema?: () => Promise<Database>;
Expand Down
Loading

0 comments on commit 6f9253f

Please sign in to comment.