Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4be50d

Browse files
committed
feat: add is_really_closed feature to non-async postgres lib
1 parent720897d commite4be50d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

‎postgres/src/client.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ impl Client {
487487
self.connection.block_on(self.client.batch_execute(query))
488488
}
489489

490+
/// Check the connection is alive and wait for the confirmation.
491+
pubfncheck_connection(&mutself) ->Result<(),Error>{
492+
self.connection.block_on(self.client.check_connection())
493+
}
494+
490495
/// Begins a new database transaction.
491496
///
492497
/// The transaction will roll back by default - use the `commit` method to commit it.

‎postgres/src/test.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,24 @@ fn check_send() {
508508
is_send::<Statement>();
509509
is_send::<Transaction<'_>>();
510510
}
511+
512+
#[test]
513+
fnis_closed(){
514+
letmut client =Client::connect("host=localhost port=5433 user=postgres",NoTls).unwrap();
515+
assert!(!client.is_closed());
516+
client.check_connection().unwrap();
517+
518+
let row = client.query_one("select pg_backend_pid()",&[]).unwrap();
519+
let pid:i32 = row.get(0);
520+
521+
{
522+
letmut client2 =Client::connect("host=localhost port=5433 user=postgres",NoTls).unwrap();
523+
client2
524+
.query("SELECT pg_terminate_backend($1)",&[&pid])
525+
.unwrap();
526+
}
527+
528+
assert!(!client.is_closed());
529+
client.check_connection().unwrap_err();
530+
assert!(client.is_closed());
531+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp