Skip to content

Commit

Permalink
Implement FromKeyValue for affected struct
Browse files Browse the repository at this point in the history
  • Loading branch information
minshao committed Feb 15, 2024
1 parent f0ece06 commit 8cd3e52
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ oinq = { git = "https://github.com/petabi/oinq.git", tag = "0.9.1" }
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls-native-roots",
] }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "037bd09b" }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "41ebf117" }
roxy = { git = "https://github.com/aicers/roxy.git", tag = "0.2.1" }
rustls = "0.21"
rustls-native-certs = "0.6"
Expand Down
5 changes: 2 additions & 3 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use num_traits::ToPrimitive;
use review_database::{
self as database, types::FromKeyValue, Database, Direction, IterableMap, Role, Store,
};
use serde::de::DeserializeOwned;
use std::{
cmp,
collections::HashMap,
Expand Down Expand Up @@ -449,7 +448,7 @@ fn load_edges<I, R, N, A, NodesField>(
) -> Result<Connection<String, N, A, EmptyFields, NodesField>>
where
I: database::Iterable<R>,
R: DeserializeOwned + database::UniqueKey,
R: database::types::FromKeyValue + database::UniqueKey,
N: From<R> + OutputType,
A: ObjectType,
NodesField: ConnectionNameType,
Expand Down Expand Up @@ -506,7 +505,7 @@ fn collect_edges<I, R>(
) -> (Vec<anyhow::Result<R>>, bool)
where
I: database::Iterable<R>,
R: DeserializeOwned + database::UniqueKey,
R: database::types::FromKeyValue + database::UniqueKey,
{
let edges: Box<dyn Iterator<Item = _>> = if let Some(cursor) = from {
let mut edges: Box<dyn Iterator<Item = _>> = Box::new(
Expand Down
7 changes: 7 additions & 0 deletions src/graphql/allow_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use async_graphql::{
Context, InputObject, Object, Result, ID,
};
use bincode::Options;
use database::types::FromKeyValue;
use review_database::{self as database, Indexable, Indexed, IndexedMapUpdate, IterableMap, Store};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -140,6 +141,12 @@ pub(super) struct AllowNetwork {
description: String,
}

impl FromKeyValue for AllowNetwork {
fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result<Self> {
Ok(bincode::DefaultOptions::new().deserialize(value)?)
}
}

#[Object]
impl AllowNetwork {
async fn id(&self) -> ID {
Expand Down
7 changes: 7 additions & 0 deletions src/graphql/block_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use async_graphql::{
Context, InputObject, Object, Result, ID,
};
use bincode::Options;
use database::types::FromKeyValue;
use review_database::{self as database, Indexable, Indexed, IndexedMapUpdate, IterableMap, Store};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, sync::Arc};
Expand Down Expand Up @@ -139,6 +140,12 @@ pub(super) struct BlockNetwork {
description: String,
}

impl FromKeyValue for BlockNetwork {
fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result<Self> {
Ok(bincode::DefaultOptions::new().deserialize(value)?)
}
}

#[Object]
impl BlockNetwork {
async fn id(&self) -> ID {
Expand Down
8 changes: 7 additions & 1 deletion src/graphql/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use chrono::{DateTime, TimeZone, Utc};
pub use crud::{get_customer_id_of_review_host, get_node_settings};
use input::NodeInput;
use ipnet::Ipv4Net;
use review_database::{Indexable, Indexed};
use review_database::{types::FromKeyValue, Indexable, Indexed};
use roxy::Process as RoxyProcess;
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -212,6 +212,12 @@ impl Node {
}
}

impl FromKeyValue for Node {
fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result<Self> {
Ok(bincode::DefaultOptions::new().deserialize(value)?)
}
}

struct NodeTotalCount;

#[Object]
Expand Down
9 changes: 8 additions & 1 deletion src/graphql/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use bincode::Options;
use chrono::{DateTime, Utc};
use oinq::RequestCode;
use review_database::{
Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate, IterableMap,
types::FromKeyValue, Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate,
IterableMap,
};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, net::IpAddr};
Expand Down Expand Up @@ -85,6 +86,12 @@ pub(super) struct SamplingPolicy {
creation_time: DateTime<Utc>,
}

impl FromKeyValue for SamplingPolicy {
fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result<Self> {
Ok(bincode::DefaultOptions::new().deserialize(value)?)
}
}

#[ComplexObject]
impl SamplingPolicy {
async fn id(&self) -> ID {
Expand Down
8 changes: 7 additions & 1 deletion src/graphql/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_graphql::{
Context, Enum, InputObject, Object, Result, SimpleObject, Union,
};
use bincode::Options;
use review_database::{IterableMap, Map, MapIterator};
use review_database::{types::FromKeyValue, IterableMap, Map, MapIterator};
use serde::{Deserialize, Serialize};
use std::convert::{TryFrom, TryInto};

Expand Down Expand Up @@ -193,6 +193,12 @@ enum Template {
Unstructured(UnstructuredClusteringTemplate),
}

impl FromKeyValue for Template {
fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result<Self> {
Ok(bincode::DefaultOptions::new().deserialize(value)?)
}
}

impl Template {
fn name(&self) -> &str {
match self {
Expand Down
9 changes: 8 additions & 1 deletion src/graphql/triage/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use async_graphql::{
use bincode::Options;
use chrono::{DateTime, Utc};
use review_database::{
Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate, IterableMap,
types::FromKeyValue, Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate,
IterableMap,
};
use serde::{Deserialize, Serialize};

Expand All @@ -28,6 +29,12 @@ pub struct TriageResponse {
last_modified_time: DateTime<Utc>,
}

impl FromKeyValue for TriageResponse {
fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result<Self> {
Ok(bincode::DefaultOptions::new().deserialize(value)?)
}
}

#[ComplexObject]
impl TriageResponse {
async fn id(&self) -> ID {
Expand Down

0 comments on commit 8cd3e52

Please sign in to comment.