Structured & JSON Fields — Aquilia Documentation
Comprehensive guide and documentation for Structured & JSON Fields in the Aquilia framework. View API reference, examples, and implementation patterns.
Docs / Models / Structured Fields Structured & JSON Fields JSON storage, native array lists, range bounds, and key-value mapping (HStore) fields. JSONField Supported across all database backends (SQLite, PostgreSQL, MySQL). Handles serialization and deserialization of nested Python structures (lists, dicts) automatically. from aquilia.models.fields_module import JSONField class Product(Model): metadata = JSONField(default_factory=dict) Spatial Fields PointField and GeometryField are portable, GeoJSON-backed spatial fields — both subclass JSONField and store data as TEXT/JSONB exactly like any other JSON value. No PostGIS extension, no native geometry column type, no new dependency. This trades native spatial indexing/query operators for zero-setup portability across SQLite/PostgreSQL/MySQL. from aquilia.models import Model, GeometryField, PointField class Store(Model): name = CharField(max_length=100) location = PointField() class Region(Model): name = CharField(max_length=100) boundary = GeometryField(null=True) store = await Store.create( name="Flagship", location= , # [lon, lat] ) region = await Region.create( name="Downtown", boundary= , ) PointField requires '} — exactly 2 numeric coordinates. Any other shape or geometry type raises FieldValidationError. GeometryField accepts any standard GeoJSON geometry type: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection. # Rejected -- wrong geometry type for PointField await Store.create(name="X", location= ) # FieldValidationError: Expected a GeoJSON Point with 2 numeric coordinates [lon, lat] ... If you need native spatial indexes (PostGIS GIST, MySQL SPATIAL), spatial query operators (ST_Contains, ST_Distance), or geometry validation beyond well-formed GeoJSON shape, you'll want a dedicated PostGIS/spatial-extension integration — that's out of scope for this JSON-backed field pair, which optimizes for portability and zero setup. PostgreSQL Native Fields ArrayField Declared with a child field type. Compiles to native SQL array. from aquilia.models.fields_module import ArrayField, CharField tags = ArrayField(CharField(max_length=50), default_factory=list) HStoreField Stores key-value pairs where both keys and values are strings. from aquilia.models.fields_module import HStoreField attributes = HStoreField(default_factory=dict) RangeField Represents numeric or temporal intervals. Supported variants: IntegerRangeField, BigIntegerRangeField, DecimalRangeField, DateRangeField, DateTimeRangeField. from aquilia.models.fields_module import IntegerRangeField age_range = IntegerRangeField() Date & Time Fields QuerySet API )
Go to Homepage