shuttle-hq / shuttle-docs

The Shuttle documentation site
https://docs.shuttle.dev
Apache License 2.0
20 stars 51 forks source link

Issue with shuttle-turbo #289

Closed francisstephan closed 2 months ago

francisstephan commented 3 months ago
Path: /resources/shuttle-turso When I implement the code snippet in the docs I get the following error at compilation: error[E0277]: the trait bound TursoOutput: IntoResource<Connection> is not satisfied --> src/main.rs:17:1 17 #[shuttle_runtime::main] ^^^^^^^^^^^^^^^^^^^^^^^^ the trait IntoResource<Connection> is not implemented for TursoOutput

= help: the trait IntoResource<libsql::database::Database> is implemented for TursoOutput = help: for that trait implementation, expected libsql::database::Database, found Connection = note: this error originates in the attribute macro shuttle_runtime::main (in Nightly builds, run with -Z macro-backtrace for more info) Here is my Cargo.toml: [package] name = "chinese-writer" version = "0.1.0" edition = "2021"

[dependencies] axum = { version="0.7.5", features=["macros","form"] } lazy_static = "1.5.0" libsql = "0.5.0" serde = "1.0.207" shuttle-axum = "0.47.0" shuttle-runtime = "0.47.0" shuttle-turso = "0.47.0" tera = "1.20.0" tokio = "1.28.2" tower-http = { version="0.5.2", features=["fs"] }

and my main.rs:

use axum::{ routing::get, Router, }; use libsql::Connection; use tower_http::services::ServeDir; use shuttle_axum::ShuttleAxum; mod handlers;

[shuttle_runtime::main]

async fn app(

[shuttle_turso::Turso(

    addr="libsql://zidian-francisstephan.turso.io",
    token="{secrets.DB_TURSO_TOKEN}")]
    client: Connection

)-> shuttle_axum::ShuttleAxum { let router = Router::new() .route("/", get(handlers::index)) .nest_service("/assets", ServeDir::new("./vol/assets"));

Ok(router.into())

}

joshua-mo-143 commented 2 months ago

Hey there - thanks for letting us know!

This does looks like it needs correcting. You need to use libsql::Database as per the updated source code, as using a connection tends to time out if you don't use it for more than 10-15s and cause the connection to not work anymore.

joshua-mo-143 commented 2 months ago

Fixed by #292