rbdc_oracle/
options.rs

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)]
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)
19                .await
20                .map_err(|e| Error::from(e.to_string()))?;
21            Ok(Box::new(v) as Box<dyn Connection>)
22        })
23    }
24
25    fn set_uri(&mut self, url: &str) -> Result<(), Error> {
26        *self = OracleConnectOptions::from_str(url)?;
27        Ok(())
28    }
29}
30
31impl Default for OracleConnectOptions {
32    fn default() -> Self {
33        Self {
34            username: "scott".to_owned(),
35            password: "tiger".to_owned(),
36            connect_string: "//localhost/XE".to_owned(),
37        }
38    }
39}
40
41impl OracleConnectOptions {
42    pub fn from_str(s: &str) -> Result<Self, Error> {
43        serde_json::from_str(s).map_err(|e| Error::from(e.to_string()))
44    }
45}