1#![deny(missing_docs)]
15
16#[cfg(test)]
17mod tests;
18
19use intf::{http::Http, Interface};
20
21pub mod error;
22pub mod intf;
23pub mod orm;
24pub mod query;
25pub mod schema;
26pub mod value;
27
28pub struct Client<T>
30where
31 T: Interface,
32{
33 pub db: Option<String>,
35 pub credentials: Option<(String, String)>,
37 pub interface: T,
39}
40
41impl Default for Client<Http> {
42 fn default() -> Client<Http> {
43 let interface = Http::new("http://localhost:8123");
44 Self {
45 db: None,
46 credentials: Default::default(),
47 interface,
48 }
49 }
50}
51
52impl<T> std::fmt::Debug for Client<T>
53where
54 T: Interface + std::fmt::Debug,
55{
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 f.debug_struct("Client")
58 .field("db", &self.db)
59 .field("credentials", &self.credentials)
60 .field("interface", &self.interface)
61 .finish()
62 }
63}
64
65impl<T> Clone for Client<T>
66where
67 T: Interface + Clone,
68{
69 fn clone(&self) -> Self {
70 Self {
71 db: self.db.clone(),
72 credentials: self.credentials.clone(),
73 interface: self.interface.clone(),
74 }
75 }
76}
77
78impl<T> Client<T>
79where
80 T: Interface,
81{
82 pub fn database(mut self, db: &str) -> Self {
84 self.db = Some(db.to_string());
85 self
86 }
87
88 pub fn credentials(mut self, username: &str, password: &str) -> Self {
90 self.credentials = Some((username.to_string(), password.to_string()));
91 self
92 }
93}
94
95pub type HttpClient = Client<Http>;