Crates.io | axum_odbc |
lib.rs | axum_odbc |
version | 0.8.0 |
source | src |
created_at | 2022-05-23 16:57:39.146428 |
updated_at | 2023-11-27 18:48:49.50335 |
description | Library to Provide an ODBC-Api layer. |
homepage | |
repository | https://github.com/AscendingCreations/AxumOdbc |
max_upload_size | |
id | 591936 |
size | 34,895 |
This project is licensed under either Apache License, Version 2.0, zlib License, or MIT License, at your option.
If you need help with this library or have suggestions please go to our Discord Group
Axum ODBC uses tokio
runtime.
# Cargo.toml
[dependencies]
axum_odbc = "0.7.0"
iodbc
: Sets odbc-api to use iodbc connection manager.
use axum_odbc::{ODBCConnectionManager, blocking};
use axum::{
Router,
routing::get,
};
use std::time::Duration;
#[tokio::main]
async fn main() {
let manager = ODBCConnectionManager::new("Driver={ODBC Driver 17 for SQL Server};Server=localhost;UID=SA;PWD=My@Test@Password1;", 5);
// build our application with some routes
let app = Router::with_state(manager)
.route("/drop", get(drop_table));
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn drop_table(manager: ODBCConnectionManager) -> String {
let mut connection = manager.aquire().await.unwrap();
let sleep = || tokio::time::sleep(Duration::from_millis(50));
let _ = connection.execute_polling("DROP TABLE IF EXISTS TEST", (), sleep).await.unwrap();
"compeleted".to_string()
}