minimal working example with diesel

This commit is contained in:
2026-01-28 15:43:22 +01:00
parent 25beef5cca
commit 361bd7bc4a
17 changed files with 370 additions and 820 deletions

View File

@@ -1,19 +1,39 @@
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use colota_backend::establish_connection;
use diesel::prelude::*;
use dotenvy::dotenv;
use std::env;
pub use colota_backend::schema;
pub use colota_backend::models;
include!("handlers/locations.rs");
async fn index(req: HttpRequest) -> impl Responder { "Connection successful" }
async fn index() -> impl Responder { "Connection successful" }
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use self::schema::locations::dsl::*;
let connection = &mut establish_connection();
let results = locations
.select(Location::as_select())
.load(connection)
.expect("Error loading locations");
println!("Displaying {} locations", results.len());
HttpServer::new(|| {
App::new()
.route("/", web::get().to(index))
.service(
web::scope("/api/v1")
.service(web::resource("/locations").to(|| {
get_locations()
}))
.service(web::resource("/locations").route(web::post().to(create_location)))
// .service(web::resource("/locations").to(|| {
// // get_locations()
// }))
// .service(web::resource("/locations").route(web::post().to(create_location)))
)
})
.bind("127.0.0.1:8080")?