/// Applies a set operation in Postgres.
Applies a set operation in Postgres.
Applies a set operation in Postgres .
fn apply_set_operation(
        &self,
        conn: &e::Connection,
        key: EntityKey,
        data: Entity,
        event_source: EventSource,
    ) -> Result<(), StoreError> {
        self.check_interface_entity_uniqueness(conn, &key)?;
        // Load the entity if exists
        let existing_entity = self
            .get_entity(conn, &key.subgraph_id, &key.entity_type, &key.entity_id)
            .map_err(Error::from)?;
        // Apply the operation
        let operation = EntityOperation::Set {
            key: key.clone(),
            data,
        };
        let updated_entity = operation.apply(existing_entity)?;
        let updated_json: serde_json::Value =
            serde_json::to_value(&updated_entity).map_err(|e| {
                format_err!(
                    "Failed to set entity ({}, {}, {}) as setting it would break it: {}",
                    key.subgraph_id,
                    key.entity_type,
                    key.entity_id,
                    e
                )
            })?;
        // Either add or update the entity in Postgres
        conn.upsert(&key, &updated_json, event_source)
            .map(|_| ())
            .map_err(|e| {
                format_err!(
                    "Failed to set entity ({}, {}, {}): {}",
                    key.subgraph_id,
                    key.entity_type,
                    key.entity_id,
                    e
                )
                .into()
            })
    }
fn apply_set_operation ( & self , conn : & e :: Connection , key : EntityKey , data : Entity , event_source : EventSource , ) -> Result < ( ) , StoreError > { self . check_interface_entity_uniqueness ( conn , & key ) ? ; // Load the entity if exists let existing_entity = self . get_entity ( conn , & key . subgraph_id , & key . entity_type , & key . entity_id ) . map_err ( Error :: from ) ? ; // Apply the operation let operation = EntityOperation :: Set { key : key . clone ( ) , data , } ; let updated_entity = operation . apply ( existing_entity ) ? ; let updated_json : serde_json :: Value = serde_json :: to_value ( & updated_entity ) . map_err ( | e | { format_err ! ( " " key subgraph_id key entity_type key entity_id e ) } ) ? ; // Either add or update the entity in Postgres conn . upsert ( & key , & updated_json , event_source ) . map ( | _ | ( ) ) . map_err ( | e | { format_err ! ( " " key subgraph_id key entity_type key entity_id e ) . into ( ) } ) }
Applies a set operation in Postgres.
Applies a set operation in Postgres .
&self
conn
&e::Connection
key
EntityKey
data
Entity
event_source
EventSource