axum_odbc

Crates.ioaxum_odbc
lib.rsaxum_odbc
version0.10.0
created_at2022-05-23 16:57:39.146428+00
updated_at2025-04-25 16:03:42.418143+00
descriptionLibrary to Provide an ODBC-Api layer.
homepage
repositoryhttps://github.com/AscendingCreations/AxumOdbc
max_upload_size
id591936
size82,122
Andrew Wheeler(Genusis) (genusistimelord)

documentation

https://docs.rs/axum_odbc

README

AxumODBC

Library to Provide an ODBC-API layer.

crates.io docs.rs Minimum Rust Version

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()
}
Commit count: 39

cargo fmt