Skip to content

Commit

Permalink
Add _values to Constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
jochemvandooren committed Mar 18, 2024
1 parent 7e24cdd commit e1e0fb3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/dbt_score/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@ class Constraint:
"""Constraint for a column.
Attributes:
name: The name of the constraint.
type: The type of the constraint, e.g. `foreign_key`.
name: The name of the constraint.
expression: The expression of the constraint, e.g. `schema.other_table`.
_raw_values: The raw values of the constraint in the manifest.
"""

name: str
type: str
expression: str
name: str | None = None
expression: str | None = None
_raw_values: dict[str, Any] = field(default_factory=dict)

@classmethod
def from_raw_values(cls, raw_values: dict[str, Any]) -> "Constraint":
"""Create a constraint object from a constraint node in the manifest."""
constraint = cls(
type=raw_values["type"],
name=raw_values["name"],
expression=raw_values["expression"],
)
constraint._raw_values = raw_values
return constraint


@dataclass
Expand Down Expand Up @@ -88,11 +101,7 @@ def from_node_values(
data_type=values["data_type"],
meta=values["meta"],
constraints=[
Constraint(
name=constraint["name"],
type=constraint["type"],
expression=constraint["expression"],
)
Constraint.from_raw_values(constraint)
for constraint in values["constraints"]
],
tags=values["tags"],
Expand Down

0 comments on commit e1e0fb3

Please sign in to comment.