fromJson static method

Table fromJson(
  1. Map<String, Object?> j
)

Implementation

static Table fromJson(Map<String, Object?> j) {
  final cols = (j['columns'] as List)
      .map((c) => ColumnDef.fromJson((c as Map).cast<String, Object?>()))
      .toList();
  final cons = ((j['constraints'] as List?) ?? const [])
      .map(
          (c) => TableConstraint.fromJson((c as Map).cast<String, Object?>()))
      .toList();
  final t = Table(j['name'] as String, cols,
      constraints: cons, withoutRowid: j['withoutRowid'] == true);
  for (final r in (j['rows'] as List)) {
    t.rows.add((r as List).map((v) => jsonValueToStorage(v)).toList());
  }
  for (final idx in (j['indexes'] as List? ?? const [])) {
    final m = (idx as Map).cast<String, Object?>();
    final cols = (m['columns'] as List?)?.cast<String>();
    final collations = (m['collations'] as List?)?.cast<String>();
    t.createIndex(IndexDef(m['name'] as String, m['column'] as String,
        unique: m['unique'] == true,
        whereSql: m['where'] as String?,
        exprSql: m['expr'] as String?,
        columns: cols,
        collations: collations));
  }
  final ai = j['autoInc'];
  if (ai is Map) {
    ai.forEach((k, v) => t.autoInc[k as String] = (v as num).toInt());
  }
  return t;
}