Public
HTTP (preview)
samwillis-pglite.web.val.run
Readme

PGlite ❤️ Val Town

PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js, Bun and Deno, with no need to install any other dependencies. It is only 3mb gzipped and has support for many Postgres extensions, including pgvector.

Read more about PGlite here: http://pglite.dev

GitHub: http://github.com/electric-sql/pglite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { PGlite } from "npm:@electric-sql/pglite";
const db = await PGlite.create();
await db.exec(`
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
test TEXT,
counter INTEGER
);
INSERT INTO test (id, test, counter) VALUES (1, 'valtown', 0);
`);
export default async function(req: Request): Promise<Response> {
const res = await db.query(`
UPDATE test
SET counter = counter + 1
WHERE id = 1
RETURNING counter, test
`);
return Response.json(res.rows[0]);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 29, 2024