| Crates.io | axum_odbc |
| lib.rs | axum_odbc |
| version | 0.10.0 |
| created_at | 2022-05-23 16:57:39.146428+00 |
| updated_at | 2025-04-25 16:03:42.418143+00 |
| description | Library to Provide an ODBC-Api layer. |
| homepage | |
| repository | https://github.com/AscendingCreations/AxumOdbc |
| max_upload_size | |
| id | 591936 |
| size | 82,122 |
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 and uses odbc-api = "12.0.1" internally.
# Cargo.toml
[dependencies]
axum_odbc = "0.10.0"
iodbc: Sets odbc-api to use iodbc connection manager.
use axum::response::IntoResponse;
use axum::{routing::get, Router};
use axum_odbc::{blocking, ODBCConnectionManager};
use std::net::SocketAddr;
use tokio::net::TcpListener;
#[tokio::main]
async fn main() {
let manager = ODBCConnectionManager::new("Driver={ODBC Driver 17 for SQL Server};Server=localhost;UID=SomeUserName;PWD=My@Test@Password1;Database=Test;", 5);
// build our application with some routes
let app = Router::new()
.route("/drop", get(drop_table))
.route("/create", get(create_table))
.with_state(manager);
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
let listener = TcpListener::bind(addr).await.unwrap();
axum::serve(
listener,
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap();
}
async fn drop_table(manager: ODBCConnectionManager) -> impl IntoResponse {
let connection = manager.aquire().await.unwrap();
blocking!(
let _ = connection.execute("DROP TABLE IF EXISTS testy", (), None).unwrap();
);
"compeleted".to_string()
}
async fn create_table(manager: ODBCConnectionManager) -> impl IntoResponse {
let connection = manager.aquire().await.unwrap();
blocking!(
let _ = connection.execute(
"IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='testy' AND xtype='U')
CREATE TABLE testy (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL
);",
(),
None,
).unwrap();
);
"compeleted".to_string()
}