insertItem static method

Future<void> insertItem(
  1. String id,
  2. String type,
  3. dynamic data, {
  4. Map<String, dynamic>? metadata,
})

Implementation

static Future<void> insertItem(
  String id,
  String type,
  dynamic data, {
  Map<String, dynamic>? metadata,
}) async {
  final db = await _openDb();
  dynamic stored;
  switch (type) {
    case 'json':
      stored = utf8.encode(jsonEncode(data));
      break;
    case 'text':
      stored = utf8.encode(data.toString());
      break;
    case 'binary':
    case 'file':
    case 'blob':
      stored = data as Uint8List;
      break;
    default:
      throw Exception('Unsupported type: $type');
  }

  await db.insert(PackageConfig.tableName, {
    'id': id,
    'type': type,
    'data': stored,
    'metadata': jsonEncode(metadata ?? {}),
    'created_at': DateTime.now().millisecondsSinceEpoch,
  }, conflictAlgorithm: ConflictAlgorithm.replace);
}