@ooraini/pgquic
v0.2.0
Published
PostgreSQL client API for browsers over multiplexed WebTransport
Maintainers
Readme
@ooraini/pgquic
Connect to PostgreSQL from the browser over WebTransport.
npm
npm install @ooraini/pgquicimport { Pool, PgWebTransport } from "@ooraini/pgquic";
const transport = new PgWebTransport({
url: "https://db.example.com/v1/session",
});
const pool = new Pool({
transport,
user: "app_user",
password: "password",
database: "app",
ssl: false,
enableChannelBinding: false,
});
const result = await pool.query("select now()");For the gateway's generated certificate, supply its logged base64 certificate_sha256 value through serverCertificateHashes as shown below.
HTML
The package is a self-contained ES module and can be imported without a build step:
<script type="module">
import {
Pool,
PgWebTransport,
} from "https://cdn.jsdelivr.net/npm/@ooraini/[email protected]/dist/index.js";
const hash = "PASTE_CERTIFICATE_SHA256_FROM_PGQUIC_LOG";
const transport = new PgWebTransport({
url: "https://localhost:4433/v1/session",
serverCertificateHashes: [{
algorithm: "sha-256",
value: Uint8Array.from(atob(hash), (c) => c.charCodeAt(0)),
}],
});
const pool = new Pool({
transport,
user: "app_user",
password: "password",
database: "app",
ssl: false,
enableChannelBinding: false,
});
const result = await pool.query("select now()");
</script>Use <script type="module">; the package does not expose a global for classic scripts.
Both approaches require a pgquic gateway. The host CLI reaches PostgreSQL at 127.0.0.1:5432 by default. A gateway container is also available:
docker pull ghcr.io/ooraini/pgquic-gateway:0.2.0See the repository for gateway configuration and deployment.
