/// Look up the schema for `subgraph` and return its entity storage.
/// Returns an error if `subgraph` does not have an entry in
/// `deployment_schemas`, which can only happen if `create_schema` was not
/// called for that `subgraph`
Look up the schema for `subgraph` and return its entity storage.
Look up the schema for ` subgraph ` and return its entity storage .
pub(crate) fn new(
        conn: &PgConnection,
        subgraph: &SubgraphDeploymentId,
        store: &Store,
    ) -> Result<Self, StoreError> {
        use public::DeploymentSchemaVersion as V;
        let schema = find_schema(conn, subgraph)?
            .ok_or_else(|| StoreError::Unknown(format_err!("unknown subgraph {}", subgraph)))?;
        let storage = match schema.version {
            V::Split => {
                let table =
                    diesel_dynamic_schema::schema(schema.name.clone()).table("entities".to_owned());
                let id = table.column::<Text, _>("id".to_string());
                let entity = table.column::<Text, _>("entity".to_string());
                let data = table.column::<Jsonb, _>("data".to_string());
                let event_source = table.column::<Text, _>("event_source".to_string());
                let count_query = format!("select count(*) from \"{}\".entities", schema.name);
                Storage::Json(JsonStorage {
                    schema: schema.name,
                    subgraph: subgraph.clone(),
                    table,
                    id,
                    entity,
                    data,
                    event_source,
                    count_query,
                })
            }
            V::Relational => {
                let subgraph_schema = store.input_schema(subgraph)?;
                let layout = Layout::new(
                    &subgraph_schema.document,
                    IdType::String,
                    subgraph.clone(),
                    schema.name,
                )?;
                Storage::Relational(layout)
            }
        };
        Ok(storage)
    }
pub ( crate ) fn new ( conn : & PgConnection , subgraph : & SubgraphDeploymentId , store : & Store , ) -> Result < Self , StoreError > { use public :: DeploymentSchemaVersion as V ; let schema = find_schema ( conn , subgraph ) ? . ok_or_else ( | | StoreError :: Unknown ( format_err ! ( " " subgraph ) ) ) ? ; let storage = match schema . version { V :: Split => { let table = diesel_dynamic_schema :: schema ( schema . name . clone ( ) ) . table ( " " . to_owned ( ) ) ; let id = table . column :: < Text , _ > ( " " . to_string ( ) ) ; let entity = table . column :: < Text , _ > ( " " . to_string ( ) ) ; let data = table . column :: < Jsonb , _ > ( " " . to_string ( ) ) ; let event_source = table . column :: < Text , _ > ( " " . to_string ( ) ) ; let count_query = format ! ( " \" \" " schema name ) ; Storage :: Json ( JsonStorage { schema : schema . name , subgraph : subgraph . clone ( ) , table , id , entity , data , event_source , count_query , } ) } V :: Relational => { let subgraph_schema = store . input_schema ( subgraph ) ? ; let layout = Layout :: new ( & subgraph_schema . document , IdType :: String , subgraph . clone ( ) , schema . name , ) ? ; Storage :: Relational ( layout ) } } ; Ok ( storage ) }
Look up the schema for `subgraph` and return its entity storage.
Look up the schema for ` subgraph ` and return its entity storage .
conn
&PgConnection
subgraph
&SubgraphDeploymentId
store
&Store