Closed ghost closed 3 years ago
The entire connection moves into "transaction mode" when a transaction is started, and so the mutable borrow is used to prevent other uses at the same time in ways that could end up being broken or confusing.
If you are not in a transaction, you can use the tokio-postgres client concurrently in multiple threads, though unless you're absolutely sure you only ever need to make single one-off queries you would probably be better off using a connection pool.
Thanks
This is the signature of
Client::build_transaction
method:Can you describe why this method takes a mutable reference to the client? Is it to make the borrow checker enforce that only one transaction is active, and that the client cannot be used while a transaction is active? Are there any other reasons which require a transaction to hold a mutable reference?
Also, I wanted to know if I'm correct in assuming that a tokio-postgres client is thread safe and can be used from multiple threads without any additional synchronization constructs?