oxigeo_db_connectors/lib.rs
1//! Database connectors for OxiGeo.
2//!
3//! This crate provides connectors for various database systems with spatial data support:
4//! - MySQL/MariaDB with spatial extensions
5//! - SQLite/SpatiaLite for embedded spatial databases
6//! - MongoDB with native GeoJSON support
7//! - ClickHouse for massive-scale spatial analytics
8//! - TimescaleDB for time-series geospatial data
9//! - Cassandra/ScyllaDB for distributed spatial data storage
10//!
11//! # Features
12//!
13//! The default feature set is **100% Pure Rust**: `postgres`, `sqlite` and
14//! `clickhouse`. The `mysql`, `mongodb` and `cassandra` connectors pull
15//! non-Pure-Rust C/asm dependencies (libz-sys, ring, aws-lc-sys respectively)
16//! and are therefore **opt-in** — enable them explicitly, e.g.
17//! `features = ["mysql"]`.
18//!
19//! # Examples
20//!
21//! ## SQLite (pure Rust, enabled by default)
22//!
23//! ```no_run
24//! use oxigeo_db_connectors::sqlite::SqliteConnector;
25//!
26//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
27//! let connector = SqliteConnector::memory()?;
28//! assert!(connector.health_check()?);
29//! # Ok(())
30//! # }
31//! ```
32//!
33//! ## MySQL (opt-in `mysql` feature)
34//!
35//! ```ignore
36//! use oxigeo_db_connectors::mysql::{MySqlConfig, MySqlConnector};
37//!
38//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
39//! let config = MySqlConfig::default();
40//! let connector = MySqlConnector::new(config)?;
41//! # Ok(())
42//! # }
43//! ```
44
45#![warn(missing_docs)]
46#![deny(unsafe_code)]
47
48#[cfg(feature = "cassandra")]
49pub mod cassandra;
50#[cfg(feature = "clickhouse")]
51pub mod clickhouse;
52pub mod connection;
53pub mod error;
54#[cfg(feature = "mongodb")]
55pub mod mongodb;
56#[cfg(feature = "mysql")]
57pub mod mysql;
58pub(crate) mod sql;
59#[cfg(feature = "sqlite")]
60pub mod sqlite;
61#[cfg(feature = "postgres")]
62pub mod timescale;
63
64// Re-export common types
65pub use error::{Error, Result};
66
67/// Database connector trait (for future unified interface).
68#[async_trait::async_trait]
69pub trait DatabaseConnector: Send + Sync {
70 /// Check if the connection is healthy.
71 async fn health_check(&self) -> Result<bool>;
72
73 /// Get database version.
74 async fn version(&self) -> Result<String>;
75
76 /// List all tables/collections.
77 async fn list_tables(&self) -> Result<Vec<String>>;
78}
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83
84 #[test]
85 fn test_error_types() {
86 let err = Error::Connection("test".to_string());
87 assert!(err.to_string().contains("Connection"));
88 }
89}