type_bridge.crud.formatting¶
formatting
¶
Value formatting utilities for TypeQL.
format_value
¶
Format a Python value for TypeQL.
Handles extraction from Attribute instances and converts Python types to their TypeQL literal representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Python value to format (may be wrapped in Attribute instance) |
required |
Returns:
| Type | Description |
|---|---|
str
|
TypeQL-formatted string literal |
Examples:
>>> format_value("hello")
'"hello"'
>>> format_value(42)
'42'
>>> format_value(True)
'true'
>>> format_value(Decimal("123.45"))
'123.45dec'
Source code in type_bridge/crud/formatting.py
unwrap_attribute
¶
Extract raw value from Attribute instance.
This utility consolidates the common pattern of extracting the underlying value from Attribute instances before processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Value that may be an Attribute instance or raw value |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The raw value (value.value if Attribute, otherwise value unchanged) |
Examples:
>>> unwrap_attribute(Name("Alice"))
"Alice"
>>> unwrap_attribute("Alice")
"Alice"
>>> unwrap_attribute(42)
42