Skip to content

Commit d8a8e36

Browse files
committed
store: Don't implement FromEntityData for Entity
1 parent 4396f8a commit d8a8e36

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

store/postgres/src/deployment_store.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,12 @@ impl DeploymentStore {
769769
AttributeNames::All,
770770
)]),
771771
);
772-
let entities = store
773-
.execute_query::<Entity>(conn, site4, query)
774-
.map_err(anyhow::Error::from)?;
772+
let entities: Vec<_> = store
773+
.execute_query::<EntityVersion>(conn, site4, query)
774+
.map_err(anyhow::Error::from)?
775+
.into_iter()
776+
.map(|ev| ev.data)
777+
.collect();
775778

776779
Ok(Some(entities))
777780
})
@@ -847,7 +850,8 @@ impl DeploymentStore {
847850
query: EntityQuery,
848851
) -> Result<Vec<Entity>, QueryExecutionError> {
849852
let conn = self.get_conn()?;
850-
self.execute_query(&conn, site, query)
853+
self.execute_query::<EntityVersion>(&conn, site, query)
854+
.map(|evs| evs.into_iter().map(|ev| ev.data).collect())
851855
}
852856

853857
pub(crate) fn transact_block_operations(

store/postgres/src/relational_queries.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,6 @@ pub trait FromEntityData: Default {
279279
fn set_vid(&mut self, vid: Vid);
280280
}
281281

282-
impl FromEntityData for Entity {
283-
type Value = graph::prelude::Value;
284-
285-
fn insert_entity_data(&mut self, key: String, v: Self::Value) {
286-
self.insert(key, v);
287-
}
288-
289-
fn set_vid(&mut self, _vid: Vid) {
290-
/* ignore */
291-
}
292-
}
293-
294282
impl FromEntityData for BTreeMap<String, r::Value> {
295283
type Value = r::Value;
296284

store/postgres/tests/relational.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Test mapping of GraphQL schema to a relational schema
22
use diesel::connection::SimpleConnection as _;
33
use diesel::pg::PgConnection;
4-
use graph::data::store::Vid;
4+
use graph::data::store::{EntityVersion, Vid};
55
use graph::prelude::{
66
o, slog, tokio, web3::types::H256, DeploymentHash, Entity, EntityCollection, EntityFilter,
77
EntityKey, EntityOrder, EntityQuery, EntityRange, Logger, Schema, StopwatchMetrics, Value,
@@ -743,7 +743,7 @@ fn count_scalar_entities(conn: &PgConnection, layout: &Layout) -> usize {
743743
]);
744744
let collection = EntityCollection::All(vec![(SCALAR.to_owned(), AttributeNames::All)]);
745745
layout
746-
.query::<Entity>(
746+
.query::<EntityVersion>(
747747
&*LOGGER,
748748
&conn,
749749
collection,
@@ -941,7 +941,7 @@ impl<'a> QueryChecker<'a> {
941941
let unordered = matches!(query.order, EntityOrder::Unordered);
942942
let entities = self
943943
.layout
944-
.query::<Entity>(
944+
.query::<EntityVersion>(
945945
&*LOGGER,
946946
self.conn,
947947
query.collection,
@@ -955,7 +955,7 @@ impl<'a> QueryChecker<'a> {
955955

956956
let mut entity_ids: Vec<_> = entities
957957
.into_iter()
958-
.map(|entity| match entity.get("id") {
958+
.map(|ev| match ev.data.get("id") {
959959
Some(Value::String(id)) => id.to_owned(),
960960
Some(_) => panic!("layout.query returned entity with non-string ID attribute"),
961961
None => panic!("layout.query returned entity with no ID attribute"),
@@ -1536,7 +1536,7 @@ fn text_find(expected_entity_ids: Vec<&str>, filter: EntityFilter) {
15361536
let query = query(vec!["Ferret"]).filter(filter).asc("id");
15371537

15381538
let entities = layout
1539-
.query::<Entity>(
1539+
.query::<EntityVersion>(
15401540
&*LOGGER,
15411541
conn,
15421542
query.collection,
@@ -1550,7 +1550,7 @@ fn text_find(expected_entity_ids: Vec<&str>, filter: EntityFilter) {
15501550

15511551
let entity_ids: Vec<_> = entities
15521552
.into_iter()
1553-
.map(|entity| match entity.get("id") {
1553+
.map(|ev| match ev.data.get("id") {
15541554
Some(Value::String(id)) => id.to_owned(),
15551555
Some(_) => panic!("layout.query returned entity with non-string ID attribute"),
15561556
None => panic!("layout.query returned entity with no ID attribute"),

store/postgres/tests/relational_bytes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Test relational schemas that use `Bytes` to store ids
22
use diesel::connection::SimpleConnection as _;
33
use diesel::pg::PgConnection;
4-
use graph::data::store::Vid;
4+
use graph::data::store::{EntityVersion, Vid};
55
use graph_mock::MockMetricsRegistry;
66
use hex_literal::hex;
77
use lazy_static::lazy_static;
@@ -416,7 +416,7 @@ fn make_thing_tree(conn: &PgConnection, layout: &Layout) -> (Entity, Entity, Ent
416416
fn query() {
417417
fn fetch(conn: &PgConnection, layout: &Layout, coll: EntityCollection) -> Vec<String> {
418418
layout
419-
.query::<Entity>(
419+
.query::<EntityVersion>(
420420
&*LOGGER,
421421
conn,
422422
coll,
@@ -428,7 +428,7 @@ fn query() {
428428
)
429429
.expect("the query succeeds")
430430
.into_iter()
431-
.map(|e| e.id().expect("entities have an id"))
431+
.map(|ev| ev.data.id().expect("entities have an id"))
432432
.collect::<Vec<_>>()
433433
}
434434

0 commit comments

Comments
 (0)