zero-to-production
zero-to-production copied to clipboard
5.4.4 code at end not in branch
At the end of 5.4.4 there's some code for changing the logging. However, the code does not appear to be in any branch here. Plus, it seems that rust doesn't like it.
pub fn connection_string(&self) -> PgConnectOptions {
let mut options = self.connection_string_wo_db().database(&self.database_name);
options.log_statements(tracing_log::log::LevelFilter::Trace);
options
}
and the errors im getting are:
error[E0382]: use of moved value: `options`
--> src/configuration.rs:37:9
|
35 | let options = self.connection_string_wo_db().database(&self.database_name);
| ------- move occurs because `options` has type `PgConnectOptions`, which does not implement the `Copy` trait
36 | options.log_statements(tracing_log::log::LevelFilter::Trace);
| ---------------------------------------------------- `options` moved due to this method call
37 | options
| ^^^^^^^ value used here after move
|
note: `log_statements` takes ownership of the receiver `self`, which moves `options`
--> /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.2/src/connection.rs:198:23
|
198 | fn log_statements(self, level: LevelFilter) -> Self;
| ^^^^
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
36 | options.clone().log_statements(tracing_log::log::LevelFilter::Trace);
| ++++++++
Is this suppose to work like how it does in the book? Or should I ignore it?
This logging option is no longer set in the latest version of the book IIRC. See https://github.com/LukeMathWalker/zero-to-production/blob/a48a2a24720f820432a33b070c807b2f448b625f/src/configuration.rs#L51
This is still present in the 20240128 version of the book (at least in both PDF versions)
The latest version I can see on Gumroad is 20230219 and has the problem mentioned here; is there some place I can get a later version? :)
Edit: I found a fix on Discord:
pub fn with_db(&self) -> PgConnectOptions {
self.without_db()
.database(&self.database_name)
.log_statements(tracing_log::log::LevelFilter::Trace)
}
See if you are not forgetting to add use sqlx::ConnectOptions;
It fixed for me.
This has been fixed in the next book release. Closing!