Skip to content

Commit 5788628

Browse files
committed
Added PGLite example [skip ci]
1 parent db6384e commit 5788628

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Or check out some examples:
3838
- [Morgan fingerprints](examples/rdkit/example.js) with RDKit.js
3939
- [Recommendations](examples/disco/example.js) with Disco
4040
- [Horizontal scaling](examples/citus/example.js) with Citus
41+
- [WebAssembly](examples/pglite/example.js) with PGLite
4142
- [Bulk loading](examples/loading/example.js) with `COPY`
4243

4344
## node-postgres

examples/pglite/example.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PGlite } from '@electric-sql/pglite';
2+
import { vector } from '@electric-sql/pglite/vector';
3+
4+
const db = new PGlite({extensions: {vector}});
5+
6+
await db.query('CREATE EXTENSION IF NOT EXISTS vector');
7+
await db.query('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))');
8+
await db.query("INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]')");
9+
await db.query('CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)');
10+
11+
const { rows } = await db.query("SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5");
12+
console.log(rows);

examples/pglite/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"type": "module",
4+
"dependencies": {
5+
"@electric-sql/pglite": "^0.2.0"
6+
}
7+
}

0 commit comments

Comments
 (0)