Files
abode/src/db/postgres/url.ts
T
codingetandClaude 4521274a27 feat: add PostgreSQL backend
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>
2026-07-20 02:00:10 +00:00

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 };
}