@clickup/pg-microsharding
Version:
Microshards support for PostgreSQL
15 lines (12 loc) • 444 B
text/typescript
export function parseLsn(lsn: string): bigint {
const [a, b] = lsn.split("/").map((x) => BigInt(parseInt(x, 16)));
return (a << BigInt(32)) + b;
}
export function isLsn(lsn: string): boolean {
return !!lsn.match(/^[0-9a-f]+\/[0-9a-f]+$/i);
}
export function subtractLsn(lsn1: string, lsn2: string): number | null {
return isLsn(lsn1) && isLsn(lsn2)
? Math.max(0, Math.round(Number(parseLsn(lsn1) - parseLsn(lsn2))))
: null;
}