Skip to content

Commit bbfecd0

Browse files
committed
sentry - move postgres fields into primitives
1 parent aa8f6d2 commit bbfecd0

File tree

4 files changed

+17
-41
lines changed

4 files changed

+17
-41
lines changed

primitives/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ pub mod util {
2525
pub mod serde;
2626
}
2727
pub mod validator;
28+
#[cfg(feature = "postgres")]
29+
pub mod postgres {
30+
pub mod field {
31+
pub use bignum::BigNumPg;
32+
pub use channel_id::ChannelIdPg;
33+
34+
mod bignum;
35+
mod channel_id;
36+
}
37+
}
2838

2939
pub use self::ad_unit::AdUnit;
3040
pub use self::balances_map::BalancesMap;

sentry/src/db/field/bignum.rs renamed to primitives/src/postgres/field/bignum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::error::Error;
22

3-
use bb8_postgres::tokio_postgres::types::{FromSql, IsNull, ToSql, Type};
3+
use postgres_types::{FromSql, IsNull, ToSql, Type};
44

5+
use crate::BigNum;
56
use bytes::BytesMut;
6-
use primitives::BigNum;
77

88
#[derive(Debug)]
9-
pub(crate) struct BigNumPg(BigNum);
9+
pub struct BigNumPg(BigNum);
1010

1111
impl Into<BigNum> for BigNumPg {
1212
fn into(self) -> BigNum {
Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use std::error::Error;
22

3-
use bb8_postgres::tokio_postgres::types::{FromSql, IsNull, ToSql, Type};
4-
5-
use bytes::BytesMut;
6-
use primitives::channel::ChannelId;
3+
use crate::ChannelId;
4+
use postgres_types::{FromSql, Type};
75

86
#[derive(Debug)]
9-
pub(crate) struct ChannelIdPg(ChannelId);
7+
pub struct ChannelIdPg(ChannelId);
108

119
impl Into<ChannelId> for ChannelIdPg {
1210
fn into(self) -> ChannelId {
@@ -19,7 +17,6 @@ impl<'a> FromSql<'a> for ChannelIdPg {
1917
let str_slice = <&str as FromSql>::from_sql(ty, raw)?;
2018

2119
// @TODO: Add this check back!
22-
2320
// if result.len() != 32 {
2421
// return Err(DomainError::InvalidArgument(format!(
2522
// "Invalid validator id value {}",
@@ -30,21 +27,7 @@ impl<'a> FromSql<'a> for ChannelIdPg {
3027
let mut id: [u8; 32] = [0; 32];
3128
id.copy_from_slice(&hex::decode(str_slice)?);
3229

33-
Ok(ChannelIdPg(id))
34-
}
35-
36-
fn accepts(ty: &Type) -> bool {
37-
match *ty {
38-
Type::TEXT | Type::VARCHAR => true,
39-
_ => false,
40-
}
41-
}
42-
}
43-
44-
impl ToSql for ChannelIdPg {
45-
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
46-
let string = hex::encode(&self.0);
47-
<String as ToSql>::to_sql(&string, ty, w)
30+
Ok(ChannelIdPg(id.into()))
4831
}
4932

5033
fn accepts(ty: &Type) -> bool {
@@ -53,13 +36,4 @@ impl ToSql for ChannelIdPg {
5336
_ => false,
5437
}
5538
}
56-
57-
fn to_sql_checked(
58-
&self,
59-
ty: &Type,
60-
out: &mut BytesMut,
61-
) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
62-
let string = hex::encode(&self.0);
63-
<String as ToSql>::to_sql_checked(&string, ty, out)
64-
}
6539
}

sentry/src/db.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ use lazy_static::lazy_static;
88

99
pub type DbPool = Pool<PostgresConnectionManager<NoTls>>;
1010

11-
pub mod field {
12-
pub(crate) use bignum::BigNumPg;
13-
pub(crate) use channel_id::ChannelIdPg;
14-
15-
mod bignum;
16-
mod channel_id;
17-
}
18-
1911
lazy_static! {
2012
static ref REDIS_URL: String =
2113
std::env::var("REDIS_URL").unwrap_or_else(|_| String::from("redis://127.0.0.1:6379"));

0 commit comments

Comments
 (0)