Skip to content

Commit f25e41f

Browse files
committed
chore(outbound-pg): Extract pg module into its own file
Signed-off-by: Konstantin Shabanov <[email protected]>
1 parent 126ee2e commit f25e41f

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

sdk/rust/src/lib.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,54 +48,7 @@ pub mod redis {
4848

4949
/// Implementation of the spin postgres db interface.
5050
#[allow(missing_docs)]
51-
pub mod pg {
52-
wit_bindgen_rust::import!("../../wit/ephemeral/outbound-pg.wit");
53-
54-
/// Exports the generated outbound Pg items.
55-
pub use outbound_pg::*;
56-
57-
impl TryFrom<&DbValue> for i32 {
58-
type Error = anyhow::Error;
59-
60-
fn try_from(value: &DbValue) -> Result<Self, Self::Error> {
61-
match value {
62-
DbValue::Int32(n) => Ok(*n),
63-
_ => Err(anyhow::anyhow!(
64-
"Expected integer from database but got {:?}",
65-
value
66-
)),
67-
}
68-
}
69-
}
70-
71-
impl TryFrom<&DbValue> for String {
72-
type Error = anyhow::Error;
73-
74-
fn try_from(value: &DbValue) -> Result<Self, Self::Error> {
75-
match value {
76-
DbValue::Str(s) => Ok(s.to_owned()),
77-
_ => Err(anyhow::anyhow!(
78-
"Expected string from the DB but got {:?}",
79-
value
80-
)),
81-
}
82-
}
83-
}
84-
85-
impl TryFrom<&DbValue> for i64 {
86-
type Error = anyhow::Error;
87-
88-
fn try_from(value: &DbValue) -> Result<Self, Self::Error> {
89-
match value {
90-
DbValue::Int64(n) => Ok(*n),
91-
_ => Err(anyhow::anyhow!(
92-
"Expected integer from the DB but got {:?}",
93-
value
94-
)),
95-
}
96-
}
97-
}
98-
}
51+
pub mod pg;
9952

10053
/// Implementation of the spin config interface.
10154
#[allow(missing_docs)]

sdk/rust/src/pg.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
wit_bindgen_rust::import!("../../wit/ephemeral/outbound-pg.wit");
3+
4+
/// Exports the generated outbound Pg items.
5+
pub use outbound_pg::*;
6+
7+
impl TryFrom<&DbValue> for i32 {
8+
type Error = anyhow::Error;
9+
10+
fn try_from(value: &DbValue) -> Result<Self, Self::Error> {
11+
match value {
12+
DbValue::Int32(n) => Ok(*n),
13+
_ => Err(anyhow::anyhow!(
14+
"Expected integer from database but got {:?}",
15+
value
16+
)),
17+
}
18+
}
19+
}
20+
21+
impl TryFrom<&DbValue> for String {
22+
type Error = anyhow::Error;
23+
24+
fn try_from(value: &DbValue) -> Result<Self, Self::Error> {
25+
match value {
26+
DbValue::Str(s) => Ok(s.to_owned()),
27+
_ => Err(anyhow::anyhow!(
28+
"Expected string from the DB but got {:?}",
29+
value
30+
)),
31+
}
32+
}
33+
}
34+
35+
impl TryFrom<&DbValue> for i64 {
36+
type Error = anyhow::Error;
37+
38+
fn try_from(value: &DbValue) -> Result<Self, Self::Error> {
39+
match value {
40+
DbValue::Int64(n) => Ok(*n),
41+
_ => Err(anyhow::anyhow!(
42+
"Expected integer from the DB but got {:?}",
43+
value
44+
)),
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)