fix: fmt + update pg
This commit is contained in:
parent
a62ba79724
commit
2f0716b6cf
2
postgres
2
postgres
@ -1 +1 @@
|
|||||||
Subproject commit 6c6a266c1449a5d754d1b3771df58ad5dbbf7b02
|
Subproject commit c7abba1e135e0be13cc857c4b8f9e86d8fc51b45
|
@ -31,40 +31,44 @@ impl<Db> HashedTextExt for HashedTextExtImpl<Db> where Db: Postgres
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::{any::Any, panic::AssertUnwindSafe};
|
use std::any::Any;
|
||||||
|
use std::panic::AssertUnwindSafe;
|
||||||
|
|
||||||
use postgres::types::{Type, ToSql, private::BytesMut, FromSql};
|
use postgres::types::private::BytesMut;
|
||||||
|
use postgres::types::{FromSql, ToSql, Type};
|
||||||
|
|
||||||
use crate::{postgres::{test::{Client, Row}, PostgresImpl, Postgres}};
|
use super::{HashedText, HashedTextExt, HashedTextExtImpl};
|
||||||
|
use crate::postgres::test::{Client, Row};
|
||||||
use super::{HashedTextExtImpl, HashedTextExt, HashedText};
|
use crate::postgres::{Postgres, PostgresImpl};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hashed_text_matches_fn_call() {
|
fn hashed_text_matches_fn_call() {
|
||||||
let client = || Client {
|
let client = || Client { query_one: Box::new(|_, q, ps| {
|
||||||
query_one: Box::new(|_, q, ps| {
|
assert_eq!(q.unwrap_str(), "select public.hashed_text_matches($1, public.hashed_text_of_string($2))");
|
||||||
assert_eq!(q.unwrap_str(), "select public.hashed_text_matches($1, public.hashed_text_of_string($2))");
|
|
||||||
|
|
||||||
let mut p0 = BytesMut::with_capacity(32);
|
let mut p0 = BytesMut::with_capacity(32);
|
||||||
let mut p1 = BytesMut::with_capacity(32);
|
let mut p1 = BytesMut::with_capacity(32);
|
||||||
|
|
||||||
ps[0].to_sql(&Type::TEXT, &mut p0).unwrap();
|
ps[0].to_sql(&Type::TEXT, &mut p0).unwrap();
|
||||||
ps[1].to_sql(&Type::TEXT, &mut p1).unwrap();
|
ps[1].to_sql(&Type::TEXT, &mut p1).unwrap();
|
||||||
|
|
||||||
let p0 = <&str as FromSql>::from_sql(&Type::TEXT, &p0).unwrap();
|
let p0 = <&str as FromSql>::from_sql(&Type::TEXT, &p0).unwrap();
|
||||||
let p1 = <&str as FromSql>::from_sql(&Type::TEXT, &p1).unwrap();
|
let p1 = <&str as FromSql>::from_sql(&Type::TEXT, &p1).unwrap();
|
||||||
|
|
||||||
assert_eq!(p1, "XXX");
|
assert_eq!(p1, "XXX");
|
||||||
|
|
||||||
Ok(Row::new(vec![("", Type::BOOL)]).value(Type::BOOL, p0 == "foo"))
|
Ok(Row::new(vec![("", Type::BOOL)]).value(Type::BOOL, p0 == "foo"))
|
||||||
}),
|
}),
|
||||||
..Client::default()
|
..Client::default() };
|
||||||
};
|
|
||||||
|
|
||||||
let pg = PostgresImpl::<Client<()>>::try_new(|| Ok(client()), 1).unwrap();
|
let pg = PostgresImpl::<Client<()>>::try_new(|| Ok(client()), 1).unwrap();
|
||||||
let htext = HashedTextExtImpl(unsafe {std::mem::transmute::<_, &'static PostgresImpl<Client<()>>>(&pg)});
|
let htext = HashedTextExtImpl(unsafe {
|
||||||
|
std::mem::transmute::<_, &'static PostgresImpl<Client<()>>>(&pg)
|
||||||
|
});
|
||||||
|
|
||||||
assert!(htext.matches(&HashedText(String::from("XXX")), "foo").unwrap());
|
assert!(htext.matches(&HashedText(String::from("XXX")), "foo")
|
||||||
assert!(!htext.matches(&HashedText(String::from("XXX")), "foob").unwrap());
|
.unwrap());
|
||||||
|
assert!(!htext.matches(&HashedText(String::from("XXX")), "foob")
|
||||||
|
.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ pub mod test {
|
|||||||
Transaction};
|
Transaction};
|
||||||
use postgres::types::private::BytesMut;
|
use postgres::types::private::BytesMut;
|
||||||
use postgres::types::{FromSql, ToSql, Type};
|
use postgres::types::{FromSql, ToSql, Type};
|
||||||
use postgres::{Column, GenericRow, GenericClient};
|
use postgres::{Column, GenericClient, GenericRow};
|
||||||
|
|
||||||
use super::{Postgres, PostgresImpl};
|
use super::{Postgres, PostgresImpl};
|
||||||
|
|
||||||
@ -160,14 +160,16 @@ pub mod test {
|
|||||||
|
|
||||||
impl<E> Row<E> {
|
impl<E> Row<E> {
|
||||||
pub fn new(cols: Vec<(&'static str, Type)>) -> Self {
|
pub fn new(cols: Vec<(&'static str, Type)>) -> Self {
|
||||||
Self {
|
Self { columns: cols.into_iter()
|
||||||
columns: cols.into_iter().map(|(name, ty)| Column::new(name.to_string(), ty)).collect(),
|
.map(|(name, ty)| Column::new(name.to_string(), ty))
|
||||||
values: vec![],
|
.collect(),
|
||||||
__phantom: PhantomData,
|
values: vec![],
|
||||||
}
|
__phantom: PhantomData }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value<V>(mut self, ty: Type, val: V) -> Self where V: ToSql {
|
pub fn value<V>(mut self, ty: Type, val: V) -> Self
|
||||||
|
where V: ToSql
|
||||||
|
{
|
||||||
let mut bs = BytesMut::with_capacity(128);
|
let mut bs = BytesMut::with_capacity(128);
|
||||||
val.to_sql(&ty, &mut bs).unwrap();
|
val.to_sql(&ty, &mut bs).unwrap();
|
||||||
self.values.push(bs);
|
self.values.push(bs);
|
||||||
@ -175,7 +177,8 @@ pub mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> GenericRow for Row<E> where E: core::fmt::Debug {
|
impl<E> GenericRow for Row<E> where E: core::fmt::Debug
|
||||||
|
{
|
||||||
type Error = E;
|
type Error = E;
|
||||||
|
|
||||||
fn columns(&self) -> &[Column] {
|
fn columns(&self) -> &[Column] {
|
||||||
@ -292,10 +295,7 @@ pub mod test {
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_raw<T, P, I>(&mut self,
|
fn query_raw<T, P, I>(&mut self, _: &T, _: I) -> Result<postgres::RowIter<'_>, Self::Error>
|
||||||
_: &T,
|
|
||||||
_: I)
|
|
||||||
-> Result<postgres::RowIter<'_>, Self::Error>
|
|
||||||
where T: ?Sized + postgres::ToStatement,
|
where T: ?Sized + postgres::ToStatement,
|
||||||
P: postgres::types::BorrowToSql,
|
P: postgres::types::BorrowToSql,
|
||||||
I: IntoIterator<Item = P>,
|
I: IntoIterator<Item = P>,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
use crate::hashed_text::HashedText;
|
||||||
use crate::repo::Repo;
|
use crate::repo::Repo;
|
||||||
use crate::{Email, hashed_text::HashedText};
|
use crate::Email;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||||
pub struct UserId(String);
|
pub struct UserId(String);
|
||||||
|
Loading…
Reference in New Issue
Block a user