9 breaking releases
new 0.10.0 | Apr 25, 2025 |
---|---|
0.9.0 | Jan 1, 2025 |
0.8.0 | Nov 27, 2023 |
0.6.0 | Jul 12, 2023 |
0.3.1 | Jul 26, 2022 |
#9 in #odbc
76 downloads per month
26KB
187 lines
AxumODBC
Library to Provide an ODBC-API layer.
License
This project is licensed under either Apache License, Version 2.0, zlib License, or MIT License, at your option.
Help
If you need help with this library or have suggestions please go to our Discord Group
Install
Axum ODBC uses tokio
runtime and uses odbc-api = "12.0.1" internally.
# Cargo.toml
[dependencies]
axum_odbc = "0.10.0"
Cargo Feature Flags
iodbc
: Sets odbc-api to use iodbc connection manager.
Example
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()
}
Dependencies
~7–23MB
~338K SLoC