Skip to content

Commit d2aa12a

Browse files
committed
feat(config): extend configuration with maxConnections and idleTimeout
1 parent 2171fd1 commit d2aa12a

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
"$ref": "#/definitions/connection",
88
"description": "MySQL connections settings"
99
},
10+
"maxConnections": {
11+
"type": "integer",
12+
"description": "Maximum number of open connection by tool",
13+
"default": 50
14+
},
15+
"idleTimeout": {
16+
"type": "integer",
17+
"description": "Duration of keeping idle connection open",
18+
"default": 60
19+
},
1020
"includeTables": {
1121
"$ref": "#/definitions/tableConditions",
1222
"description": "List of tables to include from the database dump"

src/Configuration.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ private function __construct(
2424
public MysqlConfig $connection,
2525
public TableCondition $includeCondition,
2626
public TableCondition $excludeCondition,
27+
public int $maxConnections,
28+
public int $idleTimeout
2729
) {
2830
}
2931

@@ -95,20 +97,30 @@ function ($errors, $error) {
9597
),
9698
$includeCondition,
9799
$excludeCondition,
100+
$data->maxConnections,
101+
$data->idleTimeout
98102
);
99103
}
100104

101-
public static function fromMySQLConfig(MysqlConfig $config): self
105+
public static function fromMySQLConfig(MysqlConfig $config, int $maxConnections = 50, int $idleTimeout = 60): self
102106
{
103-
return new self($config, StaticTableCondition::alwaysTrue(), StaticTableCondition::alwaysFalse());
107+
return new self(
108+
$config,
109+
StaticTableCondition::alwaysTrue(),
110+
StaticTableCondition::alwaysFalse(),
111+
$maxConnections,
112+
$idleTimeout
113+
);
104114
}
105115

106116
public function withIncludeCondition(TableCondition $condition): self
107117
{
108118
return new self(
109119
$this->connection,
110120
$this->includeCondition->withCondition($condition),
111-
$this->excludeCondition
121+
$this->excludeCondition,
122+
$this->maxConnections,
123+
$this->idleTimeout,
112124
);
113125
}
114126

@@ -117,7 +129,9 @@ public function withExcludeCondition(TableCondition $condition): self
117129
return new self(
118130
$this->connection,
119131
$this->includeCondition,
120-
$this->excludeCondition->withCondition($condition)
132+
$this->excludeCondition->withCondition($condition),
133+
$this->maxConnections,
134+
$this->idleTimeout,
121135
);
122136
}
123137

tests/ConfigurationTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace EcomDev\MySQL2JSONL;
1111

12-
1312
use Amp\Mysql\MysqlConfig;
1413
use EcomDev\MySQL2JSONL\Condition\AndTableCondition;
1514
use EcomDev\MySQL2JSONL\Condition\TableNameCondition;
@@ -215,4 +214,30 @@ public function createsExcludeConditions()
215214
)
216215
);
217216
}
217+
218+
#[Test]
219+
public function allowsSpecifyingMaxConnectionsAndIdleTimeout()
220+
{
221+
$this->assertEquals(
222+
Configuration::fromMysqlConfig(
223+
MysqlConfig::fromAuthority("db", "root", "", "magento")
224+
->withSqlMode('')
225+
->withCharset('utf8mb4', 'utf8mb4_unicode_ci'),
226+
10,
227+
5
228+
),
229+
Configuration::fromJSON(
230+
<<<JSON
231+
{
232+
"connection": {
233+
"host": "db",
234+
"database": "magento"
235+
},
236+
"maxConnections": 10,
237+
"idleTimeout": 5
238+
}
239+
JSON
240+
)
241+
);
242+
}
218243
}

0 commit comments

Comments
 (0)