fn update(
        &self,
        conn: &PgConnection,
        key: &EntityKey,
        data: &serde_json::Value,
        guard: Option<EntityFilter>,
        event_source: EventSource,
    ) -> Result<usize, StoreError> {
        if !guard.is_none() && key.subgraph_id != *SUBGRAPHS_ID {
            // We can only make adding additional conditions to the update
            // operation work for a query that is fully generated with
            // Diesel's DSL. Trying to combine the result of build_filter
            // with a direct query is too cumbersome because of various type
            // system gyrations. For now, we also only need update guards for
            // the subgraph of subgraphs
            panic!("update guards are only possible for the 'subgraphs' subgraph");
        }
        if let Some(filter) = guard {
            // Update for subgraph of subgraphs with a guard
            use self::subgraphs::entities;

            let filter = build_filter(filter).map_err(|e| {
                TransactionAbortError::Other(format!(
                    "invalid filter '{}' for value '{}'",
                    e.filter, e.value
                ))
            })?;

            let target = entities::table
                .filter(entities::entity.eq(&key.entity_type))
                .filter(entities::id.eq(&key.entity_id));

            Ok(diesel::update(target)
                .set((
                    entities::data.eq(entities::data.merge(&data)),
                    entities::event_source.eq(event_source.to_string()),
                ))
                .filter(filter)
                .execute(conn)?)
        } else {
            // If there is no guard (which has to include all 'normal' subgraphs),
            // we need to use a direct query since diesel::update does not like
            // dynamic tables.
            let query = format!(
                "UPDATE {}.entities
                   SET data = data || $3, event_source = $4
                   WHERE entity = $1 AND id = $2",
                self.schema
            );
            let query = diesel::sql_query(query)
                .bind::<Text, _>(&key.entity_type)
                .bind::<Text, _>(&key.entity_id)
                .bind::<Jsonb, _>(data)
                .bind::<Text, _>(event_source.to_string());
            query.execute(conn).map_err(|e| {
                format_err!(
                    "Failed to update entity ({}, {}, {}): {}",
                    key.subgraph_id,
                    key.entity_type,
                    key.entity_id,
                    e
                )
                .into()
            })
        }
    }
// Update for a split entities table, called from Table.update. It's lengthy,
// so we split it into its own helper function
Update for a split entities table, called from Table.update. It's lengthy,
so we split it into its own helper function
Update for a split entities table called from Table . update . It ' s lengthy so we split it into its own helper function
fn update(
        &self,
        conn: &PgConnection,
        key: &EntityKey,
        data: &serde_json::Value,
        guard: Option<EntityFilter>,
        event_source: EventSource,
    ) -> Result<usize, StoreError> {
        if !guard.is_none() && key.subgraph_id != *SUBGRAPHS_ID {
            // We can only make adding additional conditions to the update
            // operation work for a query that is fully generated with
            // Diesel's DSL. Trying to combine the result of build_filter
            // with a direct query is too cumbersome because of various type
            // system gyrations. For now, we also only need update guards for
            // the subgraph of subgraphs
            panic!("update guards are only possible for the 'subgraphs' subgraph");
        }
        if let Some(filter) = guard {
            // Update for subgraph of subgraphs with a guard
            use self::subgraphs::entities;
            let filter = build_filter(filter).map_err(|e| {
                TransactionAbortError::Other(format!(
                    "invalid filter '{}' for value '{}'",
                    e.filter, e.value
                ))
            })?;
            let target = entities::table
                .filter(entities::entity.eq(&key.entity_type))
                .filter(entities::id.eq(&key.entity_id));
            Ok(diesel::update(target)
                .set((
                    entities::data.eq(entities::data.merge(&data)),
                    entities::event_source.eq(event_source.to_string()),
                ))
                .filter(filter)
                .execute(conn)?)
        } else {
            // If there is no guard (which has to include all 'normal' subgraphs),
            // we need to use a direct query since diesel::update does not like
            // dynamic tables.
            let query = format!(
                "UPDATE {}.entities
                   SET data = data || $3, event_source = $4
                   WHERE entity = $1 AND id = $2",
                self.schema
            );
            let query = diesel::sql_query(query)
                .bind::<Text, _>(&key.entity_type)
                .bind::<Text, _>(&key.entity_id)
                .bind::<Jsonb, _>(data)
                .bind::<Text, _>(event_source.to_string());
            query.execute(conn).map_err(|e| {
                format_err!(
                    "Failed to update entity ({}, {}, {}): {}",
                    key.subgraph_id,
                    key.entity_type,
                    key.entity_id,
                    e
                )
                .into()
            })
        }
    }
fn update ( & self , conn : & PgConnection , key : & EntityKey , data : & serde_json :: Value , guard : Option < EntityFilter > , event_source : EventSource , ) -> Result < usize , StoreError > { if ! guard . is_none ( ) && key . subgraph_id != * SUBGRAPHS_ID { // We can only make adding additional conditions to the update // operation work for a query that is fully generated with // Diesel's DSL. Trying to combine the result of build_filter // with a direct query is too cumbersome because of various type // system gyrations. For now, we also only need update guards for // the subgraph of subgraphs panic ! ( " " ) ; } if let Some ( filter ) = guard { // Update for subgraph of subgraphs with a guard use self :: subgraphs :: entities ; let filter = build_filter ( filter ) . map_err ( | e | { TransactionAbortError :: Other ( format ! ( " " e filter e value ) ) } ) ? ; let target = entities :: table . filter ( entities :: entity . eq ( & key . entity_type ) ) . filter ( entities :: id . eq ( & key . entity_id ) ) ; Ok ( diesel :: update ( target ) . set ( ( entities :: data . eq ( entities :: data . merge ( & data ) ) , entities :: event_source . eq ( event_source . to_string ( ) ) , ) ) . filter ( filter ) . execute ( conn ) ? ) } else { // If there is no guard (which has to include all 'normal' subgraphs), // we need to use a direct query since diesel::update does not like // dynamic tables. let query = format ! ( " " self schema ) ; let query = diesel :: sql_query ( query ) . bind :: < Text , _ > ( & key . entity_type ) . bind :: < Text , _ > ( & key . entity_id ) . bind :: < Jsonb , _ > ( data ) . bind :: < Text , _ > ( event_source . to_string ( ) ) ; query . execute ( conn ) . map_err ( | e | { format_err ! ( " " key subgraph_id key entity_type key entity_id e ) . into ( ) } ) } }
Update for a split entities table, called from Table.update.
Update for a split entities table called from Table . update .
&self
conn
&PgConnection
key
&EntityKey
data
&serde_json::Value
guard
Option<EntityFilter>
event_source
EventSource
&self
conn
&PgConnection
key
&EntityKey
data
&serde_json::Value
guard
Option<EntityFilter>
event_source
EventSource