1use futures_core::future::BoxFuture;
2use rbdc::db::{ConnectOptions, Connection};
3use rbdc::Error;
4use serde::{Deserialize, Serialize};
5
6use crate::connection::OracleConnection;
7
8#[derive(Serialize, Deserialize, Debug, Clone)]
9pub struct OracleConnectOptions {
10 pub username: String,
11 pub password: String,
12 pub connect_string: String,
13}
14
15impl ConnectOptions for OracleConnectOptions {
16 fn connect(&self) -> BoxFuture<Result<Box<dyn Connection>, Error>> {
17 Box::pin(async move {
18 let v = OracleConnection::establish(self).await?;
19 Ok(Box::new(v) as Box<dyn Connection>)
20 })
21 }
22
23 fn set_uri(&mut self, url: &str) -> Result<(), Error> {
24 *self = OracleConnectOptions::from_str(url)?;
25 Ok(())
26 }
27}
28
29impl Default for OracleConnectOptions {
30 fn default() -> Self {
31 Self {
32 username: "scott".to_owned(),
33 password: "tiger".to_owned(),
34 connect_string: "//localhost/XE".to_owned(),
35 }
36 }
37}
38
39impl OracleConnectOptions {
40 pub fn from_str(s: &str) -> Result<Self, Error> {
41 serde_json::from_str(s).map_err(|e| Error::from(e.to_string()))
42 }
43}