import 'dart:convert';

import 'package:drift/drift.dart';

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

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

}