Proper jsonb field encoding
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
parent
0a8c5d1c1f
commit
74a1215554
@ -179,6 +179,12 @@ fn main() {
|
||||
print_user_details(inactive_user);
|
||||
}
|
||||
|
||||
// Delete a user based on an index for good measure
|
||||
db.collection::<User>()
|
||||
.expect("can open user collection")
|
||||
.delete::<username, _>("janesmith")
|
||||
.expect("can delete existing user");
|
||||
|
||||
println!("\n--- User Model Information ---");
|
||||
println!("User DB Prefix: {}", User::db_prefix());
|
||||
|
||||
|
@ -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)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user