PrismaEvent.forJson constructor

PrismaEvent.forJson(
  1. Map<String, dynamic> payload
)

Implementation

factory PrismaEvent.forJson(Map<String, dynamic> payload) {
  if (!isEvent(payload)) {
    throw ArgumentError('Invalid PrismaEvent payload');
  } else if (PrismaQueryEvent.isQueryEvent(payload)) {
    return PrismaQueryEvent(
      timestamp: DateTime.parse(payload['timestamp']),
      target: payload['target'],
      query: payload['fields']['query'],
      params: payload['fields']['params'] ?? '',
      duration: payload['fields']['duration_ms'] ?? 0,
    );
  }

  return PrismaLogEvent(
    timestamp: DateTime.parse(payload['timestamp']),
    target: payload['target'],
    message: payload['fields']['message'],
  );
}