pub struct PgrxSql<'a> {Show 17 fields
pub control: ControlFile,
pub graph: StableGraph<SqlGraphEntity<'a>, SqlGraphRequires>,
pub graph_root: NodeIndex,
pub graph_bootstrap: Option<NodeIndex>,
pub graph_finalize: Option<NodeIndex>,
pub schemas: HashMap<SchemaEntity<'a>, NodeIndex>,
pub extension_sqls: HashMap<ExtensionSqlEntity<'a>, NodeIndex>,
pub externs: HashMap<PgExternEntity<'a>, NodeIndex>,
pub types: HashMap<PostgresTypeEntity<'a>, NodeIndex>,
pub builtin_types: HashMap<String, NodeIndex>,
pub enums: HashMap<PostgresEnumEntity<'a>, NodeIndex>,
pub ords: HashMap<PostgresOrdEntity<'a>, NodeIndex>,
pub hashes: HashMap<PostgresHashEntity<'a>, NodeIndex>,
pub aggregates: HashMap<PgAggregateEntity<'a>, NodeIndex>,
pub triggers: HashMap<PgTriggerEntity<'a>, NodeIndex>,
pub extension_name: String,
pub versioned_so: bool,
}Expand description
A generator for SQL.
Consumes a base mapping of types (typically pgrx::DEFAULT_TYPEID_SQL_MAPPING), a
ControlFile, and collections of each SQL entity.
During construction, a Directed Acyclic Graph is formed out the dependencies. For example,
an item detect_dog(x: &[u8]) -> animals::Dog would have have a relationship with
animals::Dog.
Typically, PgrxSql types are constructed in a pgrx::pg_binary_magic!() call in a binary
out of entities collected during a pgrx::pg_module_magic!() call in a library.
Fields§
§control: ControlFile§graph: StableGraph<SqlGraphEntity<'a>, SqlGraphRequires>§graph_root: NodeIndex§graph_bootstrap: Option<NodeIndex>§graph_finalize: Option<NodeIndex>§schemas: HashMap<SchemaEntity<'a>, NodeIndex>§extension_sqls: HashMap<ExtensionSqlEntity<'a>, NodeIndex>§externs: HashMap<PgExternEntity<'a>, NodeIndex>§types: HashMap<PostgresTypeEntity<'a>, NodeIndex>§builtin_types: HashMap<String, NodeIndex>§enums: HashMap<PostgresEnumEntity<'a>, NodeIndex>§ords: HashMap<PostgresOrdEntity<'a>, NodeIndex>§hashes: HashMap<PostgresHashEntity<'a>, NodeIndex>§aggregates: HashMap<PgAggregateEntity<'a>, NodeIndex>§triggers: HashMap<PgTriggerEntity<'a>, NodeIndex>§extension_name: String§versioned_so: boolImplementations§
Source§impl<'a> PgrxSql<'a>
impl<'a> PgrxSql<'a>
pub fn build( entities: impl Iterator<Item = SqlGraphEntity<'a>>, extension_name: String, versioned_so: bool, ) -> Result<Self>
pub fn to_file(&self, file: impl AsRef<Path> + Debug) -> Result<()>
pub fn write(&self, out: &mut impl Write) -> Result<()>
pub fn to_dot(&self, file: impl AsRef<Path> + Debug) -> Result<()>
pub fn schema_alias_of(&self, item_index: &NodeIndex) -> Option<String>
pub fn schema_prefix_for(&self, target: &NodeIndex) -> String
pub fn find_type_dependency( &self, owner: &NodeIndex, ty: &dyn TypeIdentifiable, ) -> Option<NodeIndex>
pub fn schema_prefix_for_used_type( &self, owner: &NodeIndex, slot: &str, used_ty: &UsedTypeEntity<'_>, ) -> Result<String>
pub fn to_sql(&self) -> Result<String>
pub fn has_sql_declared_entity( &self, identifier: &SqlDeclared, ) -> Option<&SqlDeclaredEntity>
pub fn get_module_pathname(&self) -> String
pub fn find_matching_fn(&self, name: &str) -> Option<&PgExternEntity<'a>>
Sourcepub fn resolve_item(&self, name: &str) -> Result<NodeIndex>
pub fn resolve_item(&self, name: &str) -> Result<NodeIndex>
Resolve a single user-supplied item name to one graph node.
A match is any entity whose SQL-visible name, Rust path, or operator
symbol equals name exactly. A ::-bearing argument is treated as a
Rust path (matched only against full_path). Ambiguous hits are a
hard error.
Sourcepub fn to_sql_for_items(
&self,
item_names: &[String],
lib_name: &str,
extension_name: Option<&str>,
) -> Result<String>
pub fn to_sql_for_items( &self, item_names: &[String], lib_name: &str, extension_name: Option<&str>, ) -> Result<String>
Emit SQL for the given item names plus all transitive dependencies, in
dependency order, and substitute 'MODULE_PATHNAME' with
'$libdir/<lib_name>' so the output can be replayed directly into a
database.
When extension_name is Some(name), the emitted slice is wrapped in
BEGIN;/COMMIT; and each created object is followed by an
ALTER EXTENSION "<name>" ADD … clause so that piping the output into
a database where the extension is already installed attaches the new
objects to the extension. When None, the pre-feature behavior is
used (no transaction wrapping, no ADD clauses).
Warnings (e.g. for extension_sql!() blocks without creates = [...])
are written to stderr. Use emit_slice_with_warnings directly if you
need to capture them.