Skip to content

Commit e342c63

Browse files
committed
[js][data_repository][06_db_connection_class] Extract connection class
1 parent 45eeba9 commit e342c63

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

examples/js/js-data_repository-06_db_connection_class/src/Container.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ import {UsersSearcher} from "./UsersSearcher";
33
import {MySqlConfig} from "./MySqlConfig";
44

55
export class Container {
6-
mysqlConfig = new MySqlConfig();
7-
mysqlUserRepository = new MySqlUserRepository(this.mysqlConfig);
6+
Mysql = require('sync-mysql');
7+
8+
mysqlConfig = new MySqlConfig();
9+
mySqlConnection = new this.Mysql({
10+
host: this.mysqlConfig.host,
11+
user: this.mysqlConfig.user,
12+
password: this.mysqlConfig.password,
13+
database: this.mysqlConfig.database,
14+
port: this.mysqlConfig.port
15+
});
16+
17+
mysqlUserRepository = new MySqlUserRepository(this.mySqlConnection);
818
usersSearcher = new UsersSearcher(this.mysqlUserRepository);
919
}

examples/js/js-data_repository-06_db_connection_class/src/MySqlUserRepository.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
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-
});
2+
constructor(connection) {
3+
this.connection = connection;
114
}
125

136
searchAll() {

0 commit comments

Comments
 (0)