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