-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support for pg_notify * Examples using pg_notify * Update submodule * Add tests * Docs and fix unsubscribe
- Loading branch information
Showing
9 changed files
with
273 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script type="module"> | ||
import { PGliteWorker } from "../dist/worker/index.js"; | ||
|
||
const pg = new PGliteWorker(); | ||
|
||
const unsub = await pg.listen('test', (payload) => { | ||
console.log('Received:', payload); | ||
}); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
|
||
await pg.query('NOTIFY test, \'Hello, world!\''); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
|
||
await pg.query('NOTIFY test, \'Hello, world again!\''); | ||
|
||
await unsub(); | ||
|
||
await pg.query('NOTIFY test, \'Will not be received!\''); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script type="module"> | ||
import { PGlite } from "../dist/index.js"; | ||
|
||
const pg = new PGlite(); | ||
|
||
const unsub = await pg.listen('test', (payload) => { | ||
console.log('Received:', payload); | ||
}); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
|
||
await pg.query('NOTIFY test, \'Hello, world!\''); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
|
||
await pg.query('NOTIFY test, \'Hello, world again!\''); | ||
|
||
await unsub(); | ||
|
||
await pg.query('NOTIFY test, \'Will not be received!\''); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import test from "ava"; | ||
import { PGlite } from "../dist/index.js"; | ||
|
||
test("notify", async (t) => { | ||
const db = new PGlite(); | ||
|
||
await db.listen("test", (payload) => { | ||
t.is(payload, '321'); | ||
}); | ||
|
||
await db.query("NOTIFY test, '321'"); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
}); | ||
|
||
test("unlisten", async (t) => { | ||
const db = new PGlite(); | ||
|
||
const unsub = await db.listen("test", () => { | ||
t.fail(); | ||
}); | ||
|
||
await unsub(); | ||
|
||
await db.query("NOTIFY test"); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
t.pass(); | ||
}); | ||
|
||
test('onNotification', async (t) => { | ||
const db = new PGlite(); | ||
|
||
db.onNotification((chan, payload) => { | ||
t.is(chan, 'test'); | ||
t.is(payload, '123'); | ||
}); | ||
|
||
await db.query("LISTEN test"); | ||
await db.query("NOTIFY test, '123'"); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
}); |