Skip to content

Commit 7f521ec

Browse files
committed
[js][data_repository][05_parameter_object] Introduce MySqlConfig object
1 parent 8942b9d commit 7f521ec

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
import {MySqlUserRepository} from "./MySqlUserRepository";
22
import {UsersSearcher} from "./UsersSearcher";
3+
import {MySqlConfig} from "./MySqlConfig";
34

45
export class Container {
5-
mysqlHost = "localhost";
6-
mysqlUser = "root";
7-
mysqlPassword = "";
8-
mysqlDatabase = "super_project";
9-
mysqlPort = 3306;
10-
11-
mysqlUserRepository = new MySqlUserRepository(
12-
this.mysqlHost,
13-
this.mysqlUser,
14-
this.mysqlPassword,
15-
this.mysqlDatabase,
16-
this.mysqlPort
17-
);
6+
mysqlConfig = new MySqlConfig();
7+
mysqlUserRepository = new MySqlUserRepository(this.mysqlConfig);
188
usersSearcher = new UsersSearcher(this.mysqlUserRepository);
199
}
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+
}

examples/js/js-data_repository-05_parameter_object/src/MySqlUserRepository.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export class MySqlUserRepository {
2-
constructor(mysqlHost, mysqlUser, mysqlPassword, mysqlDatabase, mysqlPort) {
2+
constructor(config) {
33
const Mysql = require('sync-mysql');
44
this.connection = new Mysql({
5-
host: mysqlHost,
6-
user: mysqlUser,
7-
password: mysqlPassword,
8-
database: mysqlDatabase,
9-
port: mysqlPort
5+
host: config.host,
6+
user: config.user,
7+
password: config.password,
8+
database: config.database,
9+
port: config.port
1010
});
1111
}
1212

0 commit comments

Comments
 (0)