SQLResponseOf<T extends Object?>.fromData constructor

SQLResponseOf<T extends Object?>.fromData(
  1. T data, {
  2. string sql = "",
  3. string dataSetType = "table",
})

Implementation

factory SQLResponseOf.fromData(T data, {string sql = "", string dataSetType = "table"}) {
  bool haserror = false;
  string message = "";
  bool hasdata = false;
  string status = "OK";
  try {
    hasdata = data.isValid();
    if (data is Iterable) {
      status = List.from(data).isEmpty ? "empty" : "OK";
    }
    if (data is MapBase) {
      status = Map.from(data).isEmpty ? "empty" : "OK";
    }
  } catch (e) {
    message = "$e";
    haserror = true;
    status = "error";
  }

  return SQLResponseOf<T>(hasData: hasdata, sql: sql, status: status, data: data, hasError: haserror, dataSetType: dataSetType, message: message);
}