[go: up one dir, main page]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use wasm_bindgen::{JsCast, JsValue};
use worker_sys::types::Hyperdrive as HyperdriveSys;

use crate::EnvBinding;

pub struct Hyperdrive(HyperdriveSys);

unsafe impl Send for Hyperdrive {}
unsafe impl Sync for Hyperdrive {}

impl EnvBinding for Hyperdrive {
    const TYPE_NAME: &'static str = "Hyperdrive";
}

impl JsCast for Hyperdrive {
    fn instanceof(val: &JsValue) -> bool {
        val.is_instance_of::<HyperdriveSys>()
    }

    fn unchecked_from_js(val: JsValue) -> Self {
        Self(val.into())
    }

    fn unchecked_from_js_ref(val: &JsValue) -> &Self {
        unsafe { &*(val as *const JsValue as *const Self) }
    }
}

impl AsRef<JsValue> for Hyperdrive {
    fn as_ref(&self) -> &JsValue {
        &self.0
    }
}

impl From<Hyperdrive> for JsValue {
    fn from(hyperdrive: Hyperdrive) -> Self {
        JsValue::from(hyperdrive.0)
    }
}

impl Hyperdrive {
    pub fn connection_string(&self) -> String {
        self.0.connection_string()
    }

    pub fn host(&self) -> String {
        self.0.host()
    }

    pub fn port(&self) -> u16 {
        self.0.port()
    }

    pub fn user(&self) -> String {
        self.0.user()
    }

    pub fn password(&self) -> String {
        self.0.password()
    }

    pub fn database(&self) -> String {
        self.0.database()
    }
}