Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
1682
Cargo.lock
generated
Normal file
1682
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
35
Cargo.toml
Normal file
35
Cargo.toml
Normal file
@@ -0,0 +1,35 @@
|
||||
[package]
|
||||
name = "unchecked-io"
|
||||
version = "0.1.0"
|
||||
authors = ['billthemaker']
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
|
||||
name = "unchecked_io"
|
||||
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
# 1. Python Bindings for FFI
|
||||
pyo3 = { version = "0.20", features = ["extension-module"] }
|
||||
|
||||
# 2. Configuration Parsing
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_yaml = "0.9"
|
||||
|
||||
# 3. Apache Arrow
|
||||
arrow = "57.0.0"
|
||||
|
||||
# 4. Asynchronous Runtime
|
||||
tokio = { version = "1.48.0", features = ["full"] }
|
||||
|
||||
# 5. DB Connection (Postgres)
|
||||
tokio-postgres = "0.7.15"
|
||||
anyhow = "1.0.100"
|
||||
futures-util = "0.3.31"
|
||||
bytes = "1.11.0"
|
||||
byteorder = "1.5.0"
|
||||
chrono = "0.4"
|
||||
uuid = { version = "1.8", features = ["serde", "v4"] }
|
||||
0
config.yaml
Normal file
0
config.yaml
Normal file
0
setup_db.sql
Normal file
0
setup_db.sql
Normal file
0
src/config.rs
Normal file
0
src/config.rs
Normal file
58
src/lib.rs
Normal file
58
src/lib.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
// --- Declare our new modules ---
|
||||
// This tells Rust to look for src/config.rs and src/parser.rs
|
||||
mod config;
|
||||
mod parser;
|
||||
|
||||
// --- External Crates ---
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::exceptions::PyValueError;
|
||||
use tokio; // We need the tokio runtime here
|
||||
|
||||
// --- Internal Crates ---
|
||||
// We 'use' the public functions from our new modules
|
||||
use crate::config::{load_and_validate_config, ConnectorConfig};
|
||||
use crate::parser::run_db_logic;
|
||||
|
||||
|
||||
// --- THE PYTHON-CALLABLE ENTRY POINT ---
|
||||
|
||||
#[pyfunction]
|
||||
#[allow(unsafe_code)]
|
||||
#[allow(unsafe_op_in_unsafe_fn)]
|
||||
#[allow(rust_2024_compatibility)]
|
||||
fn load_data_from_config(py: Python, config_path: String) -> PyResult<()> {
|
||||
// --- Phase 1: Load and Validate Configuration ---
|
||||
// We call the function that now lives in src/config.rs
|
||||
let config: ConnectorConfig = match load_and_validate_config(&config_path) {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(PyValueError::new_err(format!("Configuration Error: {:?}", e))),
|
||||
};
|
||||
|
||||
println!("--- UncheckedIO: Schema Accepted ---");
|
||||
println!("Database: {}", config.connection_string);
|
||||
println!("Columns (in order): {:?}", config.schema.iter().map(|c| &c.column_name).collect::<Vec<_>>());
|
||||
|
||||
// --- Phase 2: Run Core Logic ---
|
||||
// We release the GIL and start our own Tokio runtime
|
||||
py.allow_threads(|| {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
// We call the function that now lives in src/parser.rs
|
||||
run_db_logic(config).await
|
||||
})
|
||||
}).map_err(|e| PyValueError::new_err(format!("Database/Runtime Error: {:?}", e)))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
// --- PYTHON MODULE EXPORT ---
|
||||
|
||||
#[pymodule]
|
||||
fn unchecked_io(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(load_data_from_config, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
0
src/parser.rs
Normal file
0
src/parser.rs
Normal file
Reference in New Issue
Block a user