-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guide example for connection pools is misleading because it doesn't import diesel's macros #950
Comments
I don't see anything obvious in the documentation about the issue, but it's been discussed a few times on IRC. The re-exports are provided primarily for convenience and a certain amount of version independence -- you can This works well for pretty much everything -- except diesel, because diesel depends heavily on its macros and they are pretty much unusable without Note that only the crate that uses diesel's macros (e.g. for Anyway, I'm not really sure about how best to change the example in question. |
I guess that's the root of my issue, the example works, but the example doesn't use diesel, it just puts some diesel connections in a pool. Maybe be a little merciful to beginners and let them know that to really use diesel you need more than what the example shows? |
As a total beginner I would prefer to see examples that immediately get me up and running. A comment in the example that says ”diesel depends heavily on its macros this will be alleviated in diesel-rs/diesel#1956” let's beginners know that it's not the ideal end state. |
For anyone else coming here from google, the solution to errors like
or perhaps these errors, which occur when you don't quite understand how rust imports work:
is to follow the instructions in the top-level bug report. |
I case anyone needs some guide... I've found this: I'm working through it right now. |
If I'm reading these right, I think most of the issues with the guide can be addressed by expanding the example to something like this: [dependencies]
diesel = "1.4"
[dependencies.rocket_contrib]
version = "0.4.2"
default-features = false
features = ["diesel_sqlite_pool", "redis_pool"] #[macro_use] extern crate rocket_contrib;
#[macro_use] extern crate diesel;
// diesel schema
mod schema;
use schema::logs;
// By using redis re-exported from rocket_contrib, we don't need to put redis
// in Cargo.toml and we are guaranteed to use the version of redis that is
// compatible with rocket_contrib.
use rocket_contrib::databases::redis;
#[database("sqlite_logs")]
struct LogsDbConn(diesel::SqliteConnection);
// Multiple databases can be created of the same or different connection types.
#[database("redis_db")]
struct RedisConn(redis::Connection)
#[get("/logs/<id>")]
fn get_logs(conn: LogsDbConn, id: usize) -> diesel::result::QueryResult<Logs> {
logs::filter(id.eq(log_id)).load(&*conn)
}
#[get("/redis/<id>")]
fn get_redis_value(conn: RedisConn, id: usize) -> Result<String, redis::RedisError> {
conn.get(id)
}
fn main() {
rocket::ignite()
.attach(LogsDbConn::fairing())
.mount("/", routes![get_logs, get_redis_value])
.launch();
}
|
Again, I agree that this is misleading (as a new Rust developer) especially if you don't know about things such as #[macro_use]. Is there any way for rocket to re-export the macros at least, so I don't end up with two versions of diesel by following the instructions above? (I'm not sure how #[macro_use] works, but I'm sure there is a way even if you have to manually re-export, like for instance |
@Hopefulfire There is a complete Rocket example (in examples/databases) for diesel. There's also the todo example. |
The 0.5 docs now point to multiple fully worked diesel examples. Hopefully this resolves the issue. |
https://rocket.rs/v0.4/guide/state/#usage
instead of this
I had to use this
Or none of the diesel macros were available. Resulting in errors like
The text was updated successfully, but these errors were encountered: