Proper jsonb field encoding
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
		@@ -28,7 +28,7 @@ where
 | 
			
		||||
    where
 | 
			
		||||
        I: Index<Model = V>,
 | 
			
		||||
        I::Key: Borrow<Q>,
 | 
			
		||||
        Q: ToString + ?Sized;
 | 
			
		||||
        Q: ToString + Serialize + core::fmt::Debug + Sync + ?Sized;
 | 
			
		||||
 | 
			
		||||
    /// Get an object from its ID. This does not use an index lookup
 | 
			
		||||
    fn get_by_id(&self, id: u32) -> Result<Option<V>, Error<Self::Error>>;
 | 
			
		||||
@@ -49,7 +49,7 @@ where
 | 
			
		||||
    where
 | 
			
		||||
        I: Index<Model = V>,
 | 
			
		||||
        I::Key: Borrow<Q>,
 | 
			
		||||
        Q: ToString + ?Sized;
 | 
			
		||||
        Q: ToString + Serialize + core::fmt::Debug + Sync + ?Sized;
 | 
			
		||||
 | 
			
		||||
    /// Delete an object with a given ID
 | 
			
		||||
    fn delete_by_id(&self, id: u32) -> Result<(), Error<Self::Error>>;
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,8 @@ use std::{
 | 
			
		||||
    collections::HashSet,
 | 
			
		||||
    path::PathBuf,
 | 
			
		||||
    sync::{
 | 
			
		||||
        Arc, Mutex,
 | 
			
		||||
        atomic::{AtomicU32, Ordering},
 | 
			
		||||
        Arc, Mutex,
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ use postgres::types::Json;
 | 
			
		||||
use postgres::{Client, NoTls};
 | 
			
		||||
use r2d2::Pool;
 | 
			
		||||
use r2d2_postgres::PostgresConnectionManager;
 | 
			
		||||
use serde::Serialize;
 | 
			
		||||
 | 
			
		||||
#[derive(Clone)]
 | 
			
		||||
pub struct Postgres {
 | 
			
		||||
@@ -165,7 +166,7 @@ where
 | 
			
		||||
    where
 | 
			
		||||
        I: heromodels_core::Index<Model = M>,
 | 
			
		||||
        I::Key: std::borrow::Borrow<Q>,
 | 
			
		||||
        Q: ToString + ?Sized,
 | 
			
		||||
        Q: ToString + Serialize + core::fmt::Debug + Sync + ?Sized,
 | 
			
		||||
    {
 | 
			
		||||
        let mut con = self.pool.get().map_err(Error::from)?;
 | 
			
		||||
 | 
			
		||||
@@ -175,7 +176,7 @@ where
 | 
			
		||||
                    "SELECT (value) FROM {} WHERE value->$1 = $2;",
 | 
			
		||||
                    Self::collection_name::<M>(),
 | 
			
		||||
                ),
 | 
			
		||||
                &[&I::key(), &key.to_string()],
 | 
			
		||||
                &[&I::field_name(), &Json(key)],
 | 
			
		||||
            )
 | 
			
		||||
            .map_err(Error::from)?
 | 
			
		||||
            .into_iter()
 | 
			
		||||
@@ -277,7 +278,7 @@ where
 | 
			
		||||
    where
 | 
			
		||||
        I: heromodels_core::Index<Model = M>,
 | 
			
		||||
        I::Key: std::borrow::Borrow<Q>,
 | 
			
		||||
        Q: ToString + ?Sized,
 | 
			
		||||
        Q: ToString + Serialize + core::fmt::Debug + Sync + ?Sized,
 | 
			
		||||
    {
 | 
			
		||||
        let mut con = self.pool.get().map_err(Error::from)?;
 | 
			
		||||
 | 
			
		||||
@@ -286,7 +287,7 @@ where
 | 
			
		||||
                "DELETE FROM {} WHERE value->$1 = $2;",
 | 
			
		||||
                Self::collection_name::<M>()
 | 
			
		||||
            ),
 | 
			
		||||
            &[&I::key(), &key.to_string()],
 | 
			
		||||
            &[&I::field_name(), &Json(key)],
 | 
			
		||||
        )
 | 
			
		||||
        .map_err(Error::from)?;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user