no-mistakes-postgres-engine 0.109.129

PostgreSQL embedded SQL extraction, schema catalog, and replay-safety analysis for no-mistakes
Documentation
use crate::embedded_dml::{embedded_call_facts_with_demand, embedded_call_facts_with_locations};
use crate::statements::SqlLocationDemand;
use crate::{extract_embedded_sql_from_source, EmbeddedSqlOptions, TrustedSqlTag};

#[test]
fn variants_and_general_source_mapped_calls_keep_the_complete_projection() {
    for name in [
        "variants-placeholders.ts",
        "source-position-interpolation.ts",
    ] {
        let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
            .join("../../fixtures/postgres-facts/embedded")
            .join(name);
        let source = std::fs::read_to_string(&path).unwrap();
        let file = extract_embedded_sql_from_source(
            &path,
            &source,
            &EmbeddedSqlOptions::configured("@example/db", &[]).with_trusted_sql_tags(&[
                TrustedSqlTag {
                    module: "@example/db".into(),
                    name: "sql".into(),
                },
            ]),
        );
        assert!(!file.calls.is_empty());
        assert!(file
            .calls
            .iter()
            .all(|call| !call.variants.is_empty() || !call.sql_source_positions.is_empty()));
        for bounds in [false, true] {
            let legacy_full = embedded_call_facts_with_locations(&file, bounds, false, true);
            let conflict_demand =
                embedded_call_facts_with_demand(&file, bounds, false, SqlLocationDemand::Conflicts);
            if name == "source-position-interpolation.ts" && !bounds {
                // Source mapping alone does not create a conflict-policy demand.
                assert!(conflict_demand.is_empty());
                continue;
            }
            assert_eq!(conflict_demand, legacy_full, "{name}");
            assert!(conflict_demand
                .iter()
                .all(|fact| fact.variant_locations.is_some()));
        }
    }
}