type_bridge.fields.base¶
base
¶
Field reference system for type-safe query building.
This module provides field descriptors and references that enable type-safe query expressions like Person.age.gt(Age(30)).
FieldRef
¶
Type-safe reference to an entity field.
Returned when accessing entity class attributes (e.g., Person.age). Provides query methods like .gt(), .lt(), etc. that return typed expressions.
Create a field reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Python field name |
required |
attr_type
|
type[T]
|
Attribute type class |
required |
entity_type
|
Any
|
Entity type that owns this field |
required |
Source code in type_bridge/fields/base.py
lt
¶
Create a less-than comparison expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
Value to compare against |
required |
Returns:
| Type | Description |
|---|---|
ComparisonExpr[T]
|
ComparisonExpr for this field < value |
Source code in type_bridge/fields/base.py
gt
¶
Create a greater-than comparison expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
Value to compare against |
required |
Returns:
| Type | Description |
|---|---|
ComparisonExpr[T]
|
ComparisonExpr for this field > value |
Source code in type_bridge/fields/base.py
lte
¶
Create a less-than-or-equal comparison expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
Value to compare against |
required |
Returns:
| Type | Description |
|---|---|
ComparisonExpr[T]
|
ComparisonExpr for this field <= value |
Source code in type_bridge/fields/base.py
gte
¶
Create a greater-than-or-equal comparison expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
Value to compare against |
required |
Returns:
| Type | Description |
|---|---|
ComparisonExpr[T]
|
ComparisonExpr for this field >= value |
Source code in type_bridge/fields/base.py
eq
¶
Create an equality comparison expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
Value to compare against |
required |
Returns:
| Type | Description |
|---|---|
ComparisonExpr[T]
|
ComparisonExpr for this field == value |
Source code in type_bridge/fields/base.py
neq
¶
Create a not-equal comparison expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
Value to compare against |
required |
Returns:
| Type | Description |
|---|---|
ComparisonExpr[T]
|
ComparisonExpr for this field != value |
Source code in type_bridge/fields/base.py
StringFieldRef
¶
Bases: FieldRef[T]
Field reference for String attribute types.
Provides additional string-specific operations like contains, like, regex.
Source code in type_bridge/fields/base.py
contains
¶
Create a string contains expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
Substring to search for |
required |
Returns:
| Type | Description |
|---|---|
StringExpr[T]
|
StringExpr for this field contains value |
Source code in type_bridge/fields/base.py
like
¶
Create a string pattern matching expression (regex).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
T
|
Regex pattern to match |
required |
Returns:
| Type | Description |
|---|---|
StringExpr[T]
|
StringExpr for this field like pattern |
Source code in type_bridge/fields/base.py
regex
¶
Create a string regex expression (alias for like).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
T
|
Regex pattern to match |
required |
Returns:
| Type | Description |
|---|---|
StringExpr[T]
|
StringExpr for this field matching pattern |
Source code in type_bridge/fields/base.py
NumericFieldRef
¶
Bases: FieldRef[T]
Field reference for numeric attribute types.
Provides additional numeric-specific operations like sum, avg, max, min.
Source code in type_bridge/fields/base.py
sum
¶
Create a sum aggregation expression.
Returns:
| Type | Description |
|---|---|
AggregateExpr[T]
|
AggregateExpr for sum of this field |
Source code in type_bridge/fields/base.py
avg
¶
Create an average (mean) aggregation expression.
Returns:
| Type | Description |
|---|---|
AggregateExpr[T]
|
AggregateExpr for average/mean of this field |
Source code in type_bridge/fields/base.py
max
¶
Create a maximum aggregation expression.
Returns:
| Type | Description |
|---|---|
AggregateExpr[T]
|
AggregateExpr for maximum of this field |
Source code in type_bridge/fields/base.py
min
¶
Create a minimum aggregation expression.
Returns:
| Type | Description |
|---|---|
AggregateExpr[T]
|
AggregateExpr for minimum of this field |
Source code in type_bridge/fields/base.py
median
¶
Create a median aggregation expression.
Returns:
| Type | Description |
|---|---|
AggregateExpr[T]
|
AggregateExpr for median of this field |
Source code in type_bridge/fields/base.py
std
¶
Create a standard deviation aggregation expression.
Returns:
| Type | Description |
|---|---|
AggregateExpr[T]
|
AggregateExpr for standard deviation of this field |
Source code in type_bridge/fields/base.py
FieldDescriptor
¶
Descriptor for entity fields that supports dual behavior: - Class-level access: Returns FieldRef[T] for query building - Instance-level access: Returns T (the attribute value)
Create a field descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Python field name |
required |
attr_type
|
type[T]
|
Attribute type class |
required |
Source code in type_bridge/fields/base.py
__get__
¶
__get__(instance: None, owner: Any) -> FieldRef[T]
__get__(instance: Entity, owner: Any) -> T | None
Get field value or field reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Entity | None
|
Entity instance (None for class-level access) |
required |
owner
|
Any
|
Entity class |
required |
Returns:
| Type | Description |
|---|---|
FieldRef[T] | T | None
|
FieldRef[T] for class-level access, T | None for instance-level access |
Source code in type_bridge/fields/base.py
__set__
¶
Set field value on instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Entity
|
Entity instance |
required |
value
|
T
|
Attribute value to set |
required |