queryTableInfo method

Future<TableInfo?> queryTableInfo(
  1. String name
)

查询表信息

Implementation

Future<TableInfo?> queryTableInfo(String name) async {
  List<Map<String, Object?>> maps = await _database!.rawQuery('select * from sqlite_master where name = "$name"');
  if (maps.isNotEmpty) {
    TableInfo tableInfo = TableInfo.fromJson(maps[0]);
    List<Map<String, Object?>> datas = await _database!.rawQuery("pragma table_info ('$name');");
    List<ColumnInfo> columns = [];
    for (Map<String, Object?> map in datas) {
      ColumnInfo info = ColumnInfo.fromJson(map);
      columns.add(info);
    }
    tableInfo.columns = columns;
    return tableInfo;
  }
  return null;
}