Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup lib.rs
  • Loading branch information
subrata-ms committed Jan 7, 2026
commit 8f3d8dbd8661bc7561b3d14f799109d4df97615d
89 changes: 1 addition & 88 deletions mssql_python/rust_bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,101 +1,14 @@
use pyo3::prelude::*;
use pyo3::types::PyDict;

// Import the bulk_copy module
mod bulk_copy;
use bulk_copy::BulkCopyWrapper;

/// A sample Rust-based connection class
#[pyclass]
struct RustConnection {
connection_string: String,
is_connected: bool,
}

#[pymethods]
impl RustConnection {
#[new]
fn new(connection_string: String) -> Self {
RustConnection {
connection_string,
is_connected: false,
}
}

fn connect(&mut self) -> PyResult<String> {
self.is_connected = true;
Ok(format!("Connected to: {}", self.connection_string))
}

fn disconnect(&mut self) -> PyResult<()> {
self.is_connected = false;
Ok(())
}

fn is_connected(&self) -> bool {
self.is_connected
}

fn __repr__(&self) -> String {
format!(
"RustConnection(connection_string='{}', connected={})",
self.connection_string, self.is_connected
)
}
}

/// Example function that adds two numbers
#[pyfunction]
fn add_numbers(a: i64, b: i64) -> PyResult<i64> {
Ok(a + b)
}

/// Example function that demonstrates string manipulation
#[pyfunction]
fn format_connection_string(host: String, database: String, user: String) -> PyResult<String> {
Ok(format!(
"Server={};Database={};User Id={};",
host, database, user
))
}

/// Example function to show Python dict interaction
#[pyfunction]
fn parse_connection_params(py: Python, connection_string: String) -> PyResult<Py<PyDict>> {
let dict = PyDict::new_bound(py);

// Simple parsing example
for part in connection_string.split(';') {
if let Some((key, value)) = part.split_once('=') {
dict.set_item(key.trim(), value.trim())?;
}
}

Ok(dict.unbind())
}

/// Version information
#[pyfunction]
fn rust_version() -> PyResult<String> {
Ok(format!("Rust bindings v{} (PyO3)", env!("CARGO_PKG_VERSION")))
}

/// Python module definition
/// Python module definition for mssql-python Rust bindings
#[pymodule]
fn mssql_rust_bindings(m: &Bound<'_, PyModule>) -> PyResult<()> {
// Original classes and functions
m.add_class::<RustConnection>()?;
m.add_function(wrap_pyfunction!(add_numbers, m)?)?;
m.add_function(wrap_pyfunction!(format_connection_string, m)?)?;
m.add_function(wrap_pyfunction!(parse_connection_params, m)?)?;
m.add_function(wrap_pyfunction!(rust_version, m)?)?;

// Bulk copy wrapper class
m.add_class::<BulkCopyWrapper>()?;

// Add module-level constants
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
m.add("__author__", "Microsoft SQL Server Python Team")?;

Ok(())
}
Loading