fix: fmt + update pg

This commit is contained in:
Orion Kindel 2023-07-07 12:32:36 -05:00
parent a62ba79724
commit 2f0716b6cf
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
4 changed files with 41 additions and 36 deletions

@ -1 +1 @@
Subproject commit 6c6a266c1449a5d754d1b3771df58ad5dbbf7b02
Subproject commit c7abba1e135e0be13cc857c4b8f9e86d8fc51b45

View File

@ -31,18 +31,19 @@ impl<Db> HashedTextExt for HashedTextExtImpl<Db> where Db: Postgres
#[cfg(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::{HashedTextExtImpl, HashedTextExt, HashedText};
use super::{HashedText, HashedTextExt, HashedTextExtImpl};
use crate::postgres::test::{Client, Row};
use crate::postgres::{Postgres, PostgresImpl};
#[test]
fn hashed_text_matches_fn_call() {
let client = || Client {
query_one: Box::new(|_, q, ps| {
let client = || Client { query_one: Box::new(|_, q, ps| {
assert_eq!(q.unwrap_str(), "select public.hashed_text_matches($1, public.hashed_text_of_string($2))");
let mut p0 = BytesMut::with_capacity(32);
@ -58,13 +59,16 @@ use super::{HashedTextExtImpl, HashedTextExt, HashedText};
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 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")), "foob").unwrap());
assert!(htext.matches(&HashedText(String::from("XXX")), "foo")
.unwrap());
assert!(!htext.matches(&HashedText(String::from("XXX")), "foob")
.unwrap());
}
}

View File

@ -148,7 +148,7 @@ pub mod test {
Transaction};
use postgres::types::private::BytesMut;
use postgres::types::{FromSql, ToSql, Type};
use postgres::{Column, GenericRow, GenericClient};
use postgres::{Column, GenericClient, GenericRow};
use super::{Postgres, PostgresImpl};
@ -160,14 +160,16 @@ pub mod test {
impl<E> Row<E> {
pub fn new(cols: Vec<(&'static str, Type)>) -> Self {
Self {
columns: cols.into_iter().map(|(name, ty)| Column::new(name.to_string(), ty)).collect(),
Self { columns: cols.into_iter()
.map(|(name, ty)| Column::new(name.to_string(), ty))
.collect(),
values: vec![],
__phantom: PhantomData,
}
__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);
val.to_sql(&ty, &mut bs).unwrap();
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;
fn columns(&self) -> &[Column] {
@ -292,10 +295,7 @@ pub mod test {
res
}
fn query_raw<T, P, I>(&mut self,
_: &T,
_: I)
-> Result<postgres::RowIter<'_>, Self::Error>
fn query_raw<T, P, I>(&mut self, _: &T, _: I) -> Result<postgres::RowIter<'_>, Self::Error>
where T: ?Sized + postgres::ToStatement,
P: postgres::types::BorrowToSql,
I: IntoIterator<Item = P>,

View File

@ -1,5 +1,6 @@
use crate::hashed_text::HashedText;
use crate::repo::Repo;
use crate::{Email, hashed_text::HashedText};
use crate::Email;
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct UserId(String);