pub struct PostgresProjectionGenerator { /* private fields */ }Expand description
PostgreSQL SQL projection generator using jsonb_build_object.
Generates efficient PostgreSQL SQL that projects only requested JSONB fields, reducing payload size and JSON deserialization time.
Implementations§
Source§impl PostgresProjectionGenerator
impl PostgresProjectionGenerator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create new PostgreSQL projection generator with default JSONB column name.
Default JSONB column: “data”
Sourcepub fn with_column(jsonb_column: &str) -> Self
pub fn with_column(jsonb_column: &str) -> Self
Create projection generator with custom JSONB column name.
§Arguments
jsonb_column- Name of the JSONB column in the database table
Sourcepub fn generate_projection_sql(&self, fields: &[String]) -> Result<String>
pub fn generate_projection_sql(&self, fields: &[String]) -> Result<String>
Generate PostgreSQL projection SQL for specified fields.
Generates a jsonb_build_object() call that selects only the requested fields
from the JSONB column, drastically reducing payload size.
§Arguments
fields- GraphQL field names to project from JSONB
§Returns
SQL fragment that can be used in a SELECT clause, e.g.:
jsonb_build_object('id', data->>'id', 'email', data->>'email')
§Example
let generator = PostgresProjectionGenerator::new();
let fields = vec!["id".to_string(), "email".to_string()];
let sql = generator.generate_projection_sql(&fields)?;
// Returns:
// jsonb_build_object('id', data->>'id', 'email', data->>'email')Sourcepub fn generate_select_clause(
&self,
table_alias: &str,
fields: &[String],
) -> Result<String>
pub fn generate_select_clause( &self, table_alias: &str, fields: &[String], ) -> Result<String>
Generate complete SELECT clause with projection for a table.
§Arguments
table_alias- Table alias or name in the FROM clausefields- Fields to project
§Returns
Complete SELECT clause, e.g.: SELECT jsonb_build_object(...) as data
§Example
let sql = generator.generate_select_clause("t", &fields)?;
// Returns: SELECT jsonb_build_object(...) as data