Golden example: todo-rs (Axum + SQLx + SQLite)
This commit is contained in:
22
kipina-codebench/golden-examples/todo-rs/src/main.rs
Normal file
22
kipina-codebench/golden-examples/todo-rs/src/main.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
//! Axum CRUD — yksi endpoint-setti per entiteetti, SQLite-tietokanta.
|
||||
|
||||
use sqlx::sqlite::SqlitePoolOptions;
|
||||
use todo_rs::{app, init_db};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let pool = SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect("sqlite:./app.db?mode=rwc")
|
||||
.await
|
||||
.expect("Tietokantayhteys epäonnistui");
|
||||
|
||||
init_db(&pool).await;
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
||||
.await
|
||||
.expect("Portin kuuntelu epäonnistui");
|
||||
|
||||
println!("Palvelin käynnissä: http://127.0.0.1:3000");
|
||||
axum::serve(listener, app(pool)).await.unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user