Utility functions for handling UUIDs, dates, and raw SQL queries across adapters.
// Source: https://github.com/open-condo-software/condo | License: MIT | Copyright 2020 8IQ Software Company
// Provided via justclaw.it.com; keep this notice with the code.
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
const ISO_DATETIME_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
const DATE_ONLY_RE = /^\d{4}-\d{2}-\d{2}$/
/**
* Rewrites $N placeholders in a raw SQL string to add explicit type casts
* when the corresponding parameter value can be detected as a specific type.
* This is needed because Prisma's $queryRawUnsafe sends all parameters as text,
* causing PostgreSQL to reject comparisons like `uuid = text` or `timestamptz >= text`.
*
* Detected types:
* - UUID strings → $N::uuid
* - ISO datetime strings (e.g. 2025-01-01T00:00:00.000Z)
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key