SeaQL / SeaQL/sea-orm

Axum Example not working

Open
#2,439 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-repro
Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

[DatabaseConnection] is passed as State .with_state(state) in Axum Server but this don't work. [DatabaseConnection] can't be shared across threads.

In examples/axum_example/api/src/lib.rs

...
#[derive(Clone)]
struct AppState {
    templates: Tera,
    conn: DatabaseConnection,
}
...
dotenvy::dotenv().ok();
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file");
let conn = Database::connect(db_url)
        .await
        .expect("Database connection failed");
let templates = ...
let state = AppState { templates, conn };
...
let app = Router::new()
        .route("/", get(list_posts).post(create_post))
        ...
        .with_state(state);
...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in examples/axum_example/api/src/lib.rs and inspect how AppState, DatabaseConnection, and .with_state(state) are assembled. Run the Axum example to reproduce the thread-sharing error, then verify that the example builds and starts successfully with the database connection in its state.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.