DatumSchema<E extends DatumEntityInterface> class
A declarative, runtime description of entity E's serialized shape.
fields must list every toDatumMap key, including the six core
sync fields — start from datumCoreFieldSpecs and append your payload:
final taskSchema = DatumSchema<Task>(
name: 'tasks',
fields: [...datumCoreFieldSpecs<Task>(), TaskFields.title, TaskFields.priority],
construct: (r) => Task(title: r(TaskFields.title), ...),
);
What it feeds:
- Typed reads: reader / decode (no
ascasts infromMap). - Typed writes: toMap when every field has a getter.
- SQLite columns: sqlColumns for
SqliteLocalAdapter. - Auto-migration: fingerprint + the field metadata
(
defaultValue,renamedFrom) drive the schema differ.
Constructors
-
DatumSchema({required String name, required List<
DatumFieldSpec< fields, E construct(DatumSchemaReader<E, dynamic> >E> r)?})
Properties
-
construct
→ E Function(DatumSchemaReader<
E> r)? -
Builds an entity from a typed reader; enables decode (usable as an
adapter
fromMaptear-off).final -
fields
→ List<
DatumFieldSpec< E, dynamic> > -
All serialized fields, core sync fields included.
final
- fingerprint → String
-
A stable, field-order-independent hash of the declaration
(name / value type / nullability / sqlType / renamedFrom / has-default
per field). Auto-migration stamps it after successful reconciliation to
skip introspection while the declaration is unchanged.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
The logical entity / table name.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
decode(
Map< String, dynamic> map) → E -
Decodes a raw
mapinto an entity via construct. -
diffOf(
E oldVersion, E newVersion) → Map< String, dynamic> ? -
A payload-only delta between two entity versions — the schema-driven
implementation of
DatumEntity.diff, mirroringdatum_generator'sdatumDiff: core sync fields are excluded from the comparison, and when anything changed the newmodifiedAt/versionare stamped in. Returns null when nothing changed. Requires getters on every field. -
fieldByName(
String name) → DatumFieldSpec< E, dynamic> ? -
The declared field with serialized
name, or null. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
propsOf(
E entity) → List< Object?> -
The payload field values of
entity, forEquatable.propsoverrides without restating field names (core fields come fromsuper.props): -
reader(
Map< String, dynamic> map) → DatumSchemaReader<E> -
A typed reader over a raw persisted
map. -
sqlColumns(
{SqlDialect dialect = SqlDialect.sqlite}) → Map< String, String> - Column name → SQL type for every declared field.
-
toMap(
E entity, {MapTarget target = MapTarget.local}) → Map< String, dynamic> -
Encodes an
entityinto its persisted map via each field's getter. -
toString(
) → String -
A string representation of this object.
inherited
-
validate(
Map< String, dynamic> map) → List<SchemaViolation> -
Checks a raw
mapagainst the declaration: missing non-nullable keys and undecodable values. For tests and debug tooling.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited