Skip to content

Commit

Permalink
Implement FromKeyValue
Browse files Browse the repository at this point in the history
  • Loading branch information
msk committed Feb 15, 2024
1 parent 48108ab commit b472878
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 = "c1416a69" }
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 @@ -159,6 +160,12 @@ impl AllowNetwork {
}
}

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

impl Indexable for AllowNetwork {
fn key(&self) -> Cow<[u8]> {
Cow::Borrowed(self.name.as_bytes())
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 @@ -158,6 +159,12 @@ impl BlockNetwork {
}
}

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

impl Indexable for BlockNetwork {
fn key(&self) -> Cow<[u8]> {
Cow::Borrowed(self.name.as_bytes())
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 @@ -223,6 +223,12 @@ impl NodeTotalCount {
}
}

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

impl Indexable for Node {
fn key(&self) -> Cow<[u8]> {
Cow::Borrowed(self.name.as_bytes())
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 @@ -100,6 +101,12 @@ impl SamplingPolicy {
}
}

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

struct SamplingPolicyTotalCount;

#[Object]
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 @@ -35,6 +36,12 @@ impl TriageResponse {
}
}

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

struct TriageResponseTotalCount;

#[Object]
Expand Down

0 comments on commit b472878

Please sign in to comment.