Skip to content

Commit f5e69e4

Browse files
author
g2px1
committed
added operator for query result
1 parent 34cd13c commit f5e69e4

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

examples/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ int main()
412412
/*max_pool_size*/ 32,
413413
usub::pg::PgPoolHealthConfig{
414414
.enabled = true,
415-
.interval_ms = 3000
415+
.interval_ms = 30000
416416
}
417417
);
418418

include/upq/PgTypes.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,26 @@ namespace usub::pg
117117
struct Row
118118
{
119119
std::vector<std::string> cols;
120+
121+
const std::string& operator[](size_t i) const noexcept {
122+
return cols[i];
123+
}
124+
125+
std::string& operator[](size_t i) noexcept {
126+
return cols[i];
127+
}
120128
};
121129

122130
std::vector<Row> rows;
123131

132+
const Row& operator[](size_t i) const noexcept {
133+
return rows[i];
134+
}
135+
136+
Row& operator[](size_t i) noexcept {
137+
return rows[i];
138+
}
139+
124140
bool ok{false};
125141
PgErrorCode code{PgErrorCode::Unknown};
126142

src/upq/PgHealthChecker.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,22 @@ namespace usub::pg
2121

2222
for (;;)
2323
{
24+
std::cout << "test" << std::endl;
2425
try
2526
{
26-
PgPoolHealthConfig cur = cfg_;
27-
28-
if (!cur.enabled)
29-
{
30-
co_await usub::uvent::system::this_coroutine::sleep_for(milliseconds(1000));
31-
continue;
32-
}
33-
3427
this->stats_.iterations.fetch_add(1, std::memory_order_relaxed);
3528

3629
auto res = co_await pool_.query_awaitable("SELECT 1;");
3730

3831
if (res.ok)
3932
{
4033
this->stats_.ok_checks.fetch_add(1, std::memory_order_relaxed);
41-
next_sleep = milliseconds(cur.interval_ms ? cur.interval_ms : 1000);
34+
next_sleep = milliseconds(this->cfg_.interval_ms ? this->cfg_.interval_ms : 1000);
4235
}
4336
else
4437
{
4538
this->stats_.failed_checks.fetch_add(1, std::memory_order_relaxed);
46-
auto backoff = std::min<uint64_t>(cur.interval_ms ? cur.interval_ms * 2 : 2000, 15000);
39+
auto backoff = std::min<uint64_t>(this->cfg_.interval_ms ? this->cfg_.interval_ms * 2 : 2000, 15000);
4740
next_sleep = milliseconds(backoff);
4841
}
4942
}

0 commit comments

Comments
 (0)