Mirrors the node:sqlite sub-backend structure with full migration support. Uses native pg types (UUID, JSONB, TIMESTAMPTZ) and $1/$2 parameterisation via internal ? placeholders converted at execution time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
19 lines
594 B
TypeScript
19 lines
594 B
TypeScript
export const pgProtocols = ["postgres:", "postgresql:"];
|
|
|
|
export function isPgUrl(url: string): boolean {
|
|
try {
|
|
const urlObj = new URL(url);
|
|
return pgProtocols.includes(urlObj.protocol);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function parsePgUrl(url: string): { connectionString: string; readonly: boolean } {
|
|
if (!isPgUrl(url)) throw new Error("Not a postgres: URL");
|
|
const urlObj = new URL(url);
|
|
const readonly = (urlObj.searchParams.get("readonly") ?? "0") !== "0";
|
|
urlObj.searchParams.delete("readonly");
|
|
return { connectionString: urlObj.toString(), readonly };
|
|
}
|