[go: up one dir, main page]

worker/
hyperdrive.rs

1use wasm_bindgen::{JsCast, JsValue};
2use worker_sys::types::Hyperdrive as HyperdriveSys;
3
4use crate::EnvBinding;
5
6pub struct Hyperdrive(HyperdriveSys);
7
8unsafe impl Send for Hyperdrive {}
9unsafe impl Sync for Hyperdrive {}
10
11impl EnvBinding for Hyperdrive {
12    const TYPE_NAME: &'static str = "Hyperdrive";
13}
14
15impl JsCast for Hyperdrive {
16    fn instanceof(val: &JsValue) -> bool {
17        val.is_instance_of::<HyperdriveSys>()
18    }
19
20    fn unchecked_from_js(val: JsValue) -> Self {
21        Self(val.into())
22    }
23
24    fn unchecked_from_js_ref(val: &JsValue) -> &Self {
25        unsafe { &*(val as *const JsValue as *const Self) }
26    }
27}
28
29impl AsRef<JsValue> for Hyperdrive {
30    fn as_ref(&self) -> &JsValue {
31        &self.0
32    }
33}
34
35impl From<Hyperdrive> for JsValue {
36    fn from(hyperdrive: Hyperdrive) -> Self {
37        JsValue::from(hyperdrive.0)
38    }
39}
40
41impl Hyperdrive {
42    pub fn connection_string(&self) -> String {
43        self.0.connection_string()
44    }
45
46    pub fn host(&self) -> String {
47        self.0.host()
48    }
49
50    pub fn port(&self) -> u16 {
51        self.0.port()
52    }
53
54    pub fn user(&self) -> String {
55        self.0.user()
56    }
57
58    pub fn password(&self) -> String {
59        self.0.password()
60    }
61
62    pub fn database(&self) -> String {
63        self.0.database()
64    }
65}