jsonb<D> static method

JsonTypeConverter2<D, Uint8List, Object?> jsonb<D>({
  1. required D fromJson(
    1. Object? json
    ),
  2. Object? toJson(
    1. D column
    )?,
})

Creates a type converter for storing complex Dart objects in a binary column by serializing them into the JSONB representation used by SQLite.

This requires supplying fromJson, a function responsible for mapping the parsed JSON structure to the Dart type D. Optionally, you can also be explicit about the other direction via toJson. By default, the JSONB encoder simply calls toJson() on the object.

Note that this representation is primarily useful when JSON operators are commonly used on the column to extract individual fields. The main advantage of the JSONB representation is that those operators can be implemented more efficiently. For the common case where entire JSON values are inserted and selected, prefer using a textual json2 converter for better compatibility with standard formats.

Implementation

static JsonTypeConverter2<D, Uint8List, Object?> jsonb<D>({
  required D Function(Object? json) fromJson,
  Object? Function(D column)? toJson,
}) {
  return _DefaultJsonConverter<D, Uint8List, Object?>(
    mapFromJson: fromJson,
    mapToJson: toJson ?? (value) => value,
    jsonForDb: sqlite3.jsonb,
  );
}