Skip to content

Commit 45eeba9

Browse files
committed
[js][data_repository][06_db_connection_class] Add base
1 parent 7f521ec commit 45eeba9

File tree

11 files changed

+6164
-0
lines changed

11 files changed

+6164
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.tmp/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-env"],
3+
"plugins": ["@babel/plugin-proposal-class-properties"]
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
verbose: true,
4+
cacheDirectory: './.tmp/jestCache',
5+
transform: {'^.+\\.js$': 'babel-jest'},
6+
testMatch:[ "**/tests/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ],
7+
moduleFileExtensions: ['js']
8+
};

examples/js/js-data_repository-06_db_connection_class/package-lock.json

Lines changed: 6055 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "student_grades",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"jest": {
12+
"moduleFileExtensions": [
13+
"js",
14+
"jsx"
15+
],
16+
"moduleDirectories": [
17+
"node_modules",
18+
"src"
19+
]
20+
},
21+
"devDependencies": {
22+
"@babel/core": "^7.11.6",
23+
"@babel/plugin-proposal-class-properties": "^7.10.4",
24+
"@babel/preset-env": "^7.11.5",
25+
"@jest/globals": "^26.4.2",
26+
"jest": "^26.4.2"
27+
},
28+
"dependencies": {
29+
"sync-mysql": "^3.0.1",
30+
"sync-sql": "^1.0.2"
31+
}
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {MySqlUserRepository} from "./MySqlUserRepository";
2+
import {UsersSearcher} from "./UsersSearcher";
3+
import {MySqlConfig} from "./MySqlConfig";
4+
5+
export class Container {
6+
mysqlConfig = new MySqlConfig();
7+
mysqlUserRepository = new MySqlUserRepository(this.mysqlConfig);
8+
usersSearcher = new UsersSearcher(this.mysqlUserRepository);
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class MySqlConfig {
2+
host = "localhost";
3+
user = "root";
4+
password = "";
5+
database = "super_project";
6+
port = 3306;
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class MySqlUserRepository {
2+
constructor(config) {
3+
const Mysql = require('sync-mysql');
4+
this.connection = new Mysql({
5+
host: config.host,
6+
user: config.user,
7+
password: config.password,
8+
database: config.database,
9+
port: config.port
10+
});
11+
}
12+
13+
searchAll() {
14+
return this.connection.query('SELECT * FROM users');
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class UsersSearcher {
2+
constructor(repository) {
3+
this.repository = repository;
4+
}
5+
6+
searchAll() {
7+
return this.repository.searchAll();
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class FakeUserRepository {
2+
constructor(users) {
3+
this.users = users;
4+
}
5+
6+
searchAll() {
7+
return this.users;
8+
}
9+
}

0 commit comments

Comments
 (0)