-
Notifications
You must be signed in to change notification settings - Fork 0
/
compatibility.html
73 lines (57 loc) · 1.8 KB
/
compatibility.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PGlite Test</title>
</head>
<body>
<h1>For testing compatibility across browsers</h1>
<p>Open the console to see the output.</p><p>Doesn't work in Firefox (<a href="https://github.com/electric-sql/pglite/issues/7">issue #7</a>).</p>
</body>
</html>
<script type="module">
// import { PGlite } from "./dist/index.js";
import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js";
console.log("Starting...");
// const pg = new PGlite();
const pg = new PGlite('idb://pgdata');
console.log("Waiting for ready...");
await pg.waitReady;
// process.exit(0);
console.log("Ready!");
console.log("Creating table...");
await pg.query(`
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
name TEXT
);
`);
console.log("Inserting data...");
await pg.query("INSERT INTO test (name) VALUES ('test');");
console.log("Selecting data...");
const res = await pg.query(`
SELECT * FROM test;
`);
console.log(res);
// try {
// await pg.query('1');
// } catch (e) {
// console.log('Error caught:');
// console.log(e);
// }
console.log(await pg.query("SELECT * FROM test;"));
// Test transaction
await pg.query("BEGIN;");
await pg.query("INSERT INTO test (name) VALUES ('test2');");
await pg.query("ROLLBACK;");
console.log(await pg.query("SELECT * FROM test;"));
await pg.query("BEGIN;");
await pg.query("INSERT INTO test (name) VALUES ('test3');");
await pg.query("COMMIT;");
console.log(await pg.query("SELECT * FROM test;"));
console.log("Closing...");
await pg.close();
// async timeout 1s
await new Promise((resolve) => setTimeout(resolve, 1000));
</script>