forked from mirromutth/mysql-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2001797
commit 82ee48a
Showing
8 changed files
with
1,908 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"airbnb-base" | ||
], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"no-undef": "off" | ||
}, | ||
"settings": { | ||
"import/resolver": { | ||
"node": { | ||
"extensions": [".ts"], | ||
"paths": ["./test"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-18.04 | ||
|
||
strategy: | ||
matrix: | ||
node-version: ['10.x'] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Set up MySQL Latest | ||
uses: mirromutth/mysql-action@master | ||
with: | ||
mysql version: latest | ||
mysql database: test | ||
mysql root password: ${{ secrets.DatabasePassword }} | ||
- name: npm install, build, and test | ||
run: | | ||
npm install | ||
npm run lint | ||
npm test -- --password=${{ secrets.DatabasePassword }} | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
### MacOS | ||
|
||
.DS_Store | ||
|
||
### NPM (using YARN, sorry NPM) | ||
|
||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "mysql-action", | ||
"version": "1.1.1", | ||
"description": "MySQL Github Action", | ||
"main": "build/app.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"lint": "eslint . --ext .ts", | ||
"build": "node_modules/.bin/tsc", | ||
"test": "mocha -r ts-node/register test/**/*-test.ts" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mirromutth/mysql-action.git" | ||
}, | ||
"keywords": [ | ||
"MySQL", | ||
"Action", | ||
"Github-Actions" | ||
], | ||
"author": "Mirro Mutth", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/mirromutth/mysql-action/issues" | ||
}, | ||
"homepage": "https://github.com/mirromutth/mysql-action#readme", | ||
"devDependencies": { | ||
"@types/chai": "^4.2.3", | ||
"@types/lodash": "^4.14.142", | ||
"@types/mocha": "^5.2.7", | ||
"@types/mysql": "^2.15.7", | ||
"@typescript-eslint/eslint-plugin": "^2.3.3", | ||
"@typescript-eslint/parser": "^2.3.3", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.5.1", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"mocha": "^6.2.1", | ||
"ts-node": "^8.4.1", | ||
"typescript": "^3.6.3" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.15", | ||
"mysql": "^2.17.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as _ from 'lodash/fp'; | ||
|
||
const args: { [key: string]: string } = _.pipe( | ||
_.map((value: string) => { | ||
if (!value.startsWith('--')) { | ||
return undefined; | ||
} | ||
|
||
const index = value.indexOf('=', 2); | ||
|
||
if (index < 0) { | ||
return undefined; | ||
} | ||
|
||
return [value.substring(2, index), value.substring(index + 1)]; | ||
}), | ||
_.filter((value) => value !== undefined), | ||
_.fromPairs, | ||
)(process.argv); | ||
|
||
export function required(key: string): string { | ||
const result = args[key]; | ||
|
||
if (result === undefined) { | ||
throw new TypeError(`Argument ${key} not found`); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export function optional(key: string): string | undefined { | ||
return args[key]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { promisify } from 'util'; | ||
import { createConnection } from 'mysql'; | ||
|
||
import { required } from './arguments'; | ||
|
||
export interface Queryer { | ||
init(): Promise<void>; | ||
query(sql: string): Promise<any>; | ||
close(): Promise<void>; | ||
} | ||
|
||
function createQueryer(): Queryer { | ||
const connection = createConnection({ | ||
host: 'localhost', | ||
user: 'root', | ||
password: required('password'), | ||
database: 'test', | ||
}); | ||
|
||
return { | ||
init: () => new Promise<void>((resolve, reject) => { | ||
connection.connect((err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}), | ||
query: promisify(connection.query.bind(connection)), | ||
close: () => new Promise<void>((resolve, reject) => { | ||
connection.end((err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}), | ||
}; | ||
} | ||
|
||
export default createQueryer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { expect } from 'chai'; | ||
|
||
import createQueryer from './connection'; | ||
|
||
describe('Database', () => { | ||
const queryer = createQueryer(); | ||
|
||
before('Connect', queryer.init); | ||
after('Disconnect', queryer.close); | ||
|
||
describe('#select', () => { | ||
it('should return tables for current database', async () => { | ||
const results = await queryer.query('SHOW TABLES'); | ||
expect(results).to.be.a('array'); | ||
}); | ||
it('should return informations for other database', async () => { | ||
const results = await queryer.query('SELECT * FROM information_schema.innodb_trx'); | ||
expect(results).to.be.a('array'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.