exarrow_rs/adbc/
driver.rs1use crate::adbc::Database;
7use crate::error::ConnectionError;
8use std::str::FromStr;
9
10#[derive(Debug, Clone)]
19pub struct Driver {
20 name: String,
22 version: String,
24 vendor: String,
26 description: String,
28}
29
30impl Driver {
31 pub fn new() -> Self {
38 Self {
39 name: "exarrow-rs".to_string(),
40 version: env!("CARGO_PKG_VERSION").to_string(),
41 vendor: "exarrow-rs contributors".to_string(),
42 description: "ADBC-compatible driver for Exasol with Arrow data format support"
43 .to_string(),
44 }
45 }
46
47 pub fn name(&self) -> &str {
53 &self.name
54 }
55
56 pub fn version(&self) -> &str {
62 &self.version
63 }
64
65 pub fn vendor(&self) -> &str {
71 &self.vendor
72 }
73
74 pub fn description(&self) -> &str {
80 &self.description
81 }
82
83 pub fn open(&self, connection_string: &str) -> Result<Database, ConnectionError> {
104 Database::from_str(connection_string)
105 }
106
107 pub fn validate_connection_string(&self, connection_string: &str) -> bool {
122 Database::from_str(connection_string).is_ok()
123 }
124}
125
126impl Default for Driver {
127 fn default() -> Self {
128 Self::new()
129 }
130}
131
132impl std::fmt::Display for Driver {
133 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
134 write!(f, "{} v{} ({})", self.name, self.version, self.vendor)
135 }
136}
137
138#[cfg(test)]
139mod tests {
140 use super::*;
141
142 #[test]
143 fn test_driver_creation() {
144 let driver = Driver::new();
145 assert_eq!(driver.name(), "exarrow-rs");
146 assert_eq!(driver.vendor(), "exarrow-rs contributors");
147 assert!(!driver.version().is_empty());
148 assert!(!driver.description().is_empty());
149 }
150
151 #[test]
152 fn test_driver_default() {
153 let driver = Driver::default();
154 assert_eq!(driver.name(), "exarrow-rs");
155 }
156
157 #[test]
158 fn test_driver_display() {
159 let driver = Driver::new();
160 let display = format!("{}", driver);
161 assert!(display.contains("exarrow-rs"));
162 assert!(display.contains("contributors"));
163 }
164
165 #[test]
166 fn test_driver_open_valid() {
167 let driver = Driver::new();
168 let result = driver.open("exasol://user@localhost");
169 assert!(result.is_ok());
170 }
171
172 #[test]
173 fn test_driver_open_invalid() {
174 let driver = Driver::new();
175 let result = driver.open("invalid://connection");
176 assert!(result.is_err());
177 }
178
179 #[test]
180 fn test_validate_connection_string() {
181 let driver = Driver::new();
182
183 assert!(driver.validate_connection_string("exasol://user@localhost"));
184 assert!(driver.validate_connection_string("exasol://user:pass@host:8563"));
185 assert!(driver.validate_connection_string("exasol://user@host/schema"));
186
187 assert!(!driver.validate_connection_string(""));
188 assert!(!driver.validate_connection_string("invalid"));
189 assert!(!driver.validate_connection_string("postgres://user@host"));
190 }
191}