import 'dart:convert';

import 'package:drift/drift.dart';

class StringListMapConverter extends TypeConverter<List<Map<String, dynamic>>, String> {
  @override
  List<Map<String, dynamic>> fromSql(String fromDb) {
    try {
      return (jsonDecode(fromDb) as List).cast<Map<String, dynamic>>();
    } catch(e) {
      return [];
    }
  }

  @override
  String toSql(List<Map<String, dynamic>> value) {
    return jsonEncode(value);
  }

}