Skip to main content

bind

Function bind 

Source
pub fn bind<'a>(
    db: &TabularDatabase,
    index: &ModelIndex,
    home_table: Option<&str>,
    raw: RawRef<'a>,
) -> Binding<'a>
Expand description

Resolves one extracted reference against the model.

home_table is the row-context table of the expression the reference was found in — DaxExpressionRef::home_table carries it. Resolution rules live in ModelIndex; this wrapper only turns its answers into graph-ready data:

  • qualified 'Table'[Name] → the table’s column, falling back to the model-global measure (resolve_qualified);
  • unqualified [Name] → the measure and the home-table column, both kept alive (resolve_unqualified);
  • bare table → the table (resolve_table);
  • a call whose name is a user-defined function → that function (resolve_function); built-ins resolve to nothing and stay unresolved.
use ripbi_core::{Column, Measure, ModelIndex, Table, TabularDatabase, dax};

let db = TabularDatabase {
    tables: vec![
        Table {
            name: "Sales".to_string(),
            measures: vec![Measure {
                name: "Antal".to_string(),
                expression: "0".to_string(),
                ..Default::default()
            }],
            ..Default::default()
        },
        Table {
            name: "Dato".to_string(),
            columns: vec![Column {
                name: "Antal".to_string(),
                ..Default::default()
            }],
            ..Default::default()
        },
    ],
    ..Default::default()
};
let index = ModelIndex::build(&db);

// `[Antal]` in a `Dato` row context is ambiguous: measure and column both.
let raw = dax::references("[Antal]").remove(0);
let binding = dax::bind(&db, &index, Some("Dato"), raw);
assert_eq!(binding.targets().len(), 2);

// An unknown name is data, not an error.
let raw = dax::references("[Ukendt]").remove(0);
assert!(dax::bind(&db, &index, Some("Dato"), raw).is_unresolved());