Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
cd20be5
update submodule; improve CI
tdrz Nov 5, 2025
7556a66
update submodule
tdrz Nov 5, 2025
ab17e07
update submodule
tdrz Nov 6, 2025
2826cd9
merge main
tdrz Nov 6, 2025
a2788f7
pg_dump improvements; update submodule
tdrz Nov 10, 2025
e919f7b
update submodule
tdrz Nov 11, 2025
20cc911
cleanup
tdrz Nov 11, 2025
c28028a
update submodule
tdrz Nov 11, 2025
647b5c7
refactor
tdrz Nov 11, 2025
7c63bc7
Merge remote-tracking branch 'origin/main' into tdrz/libpglite
tdrz Nov 11, 2025
185f045
update submodule
tdrz Nov 11, 2025
41ad77e
update submodule
tdrz Nov 12, 2025
c68e149
update submodule
tdrz Nov 12, 2025
2f82930
update submodule
tdrz Nov 12, 2025
445c04d
do not automatically call main; refactorings
tdrz Nov 17, 2025
c064d18
more cleanup; update submodule
tdrz Nov 17, 2025
b6d3526
cleanup
tdrz Nov 17, 2025
abce644
moved env vars to module in TS
tdrz Nov 17, 2025
cb017cd
cleanup
tdrz Nov 17, 2025
93941a5
tests fix
tdrz Nov 17, 2025
7270d06
submodule
tdrz Nov 17, 2025
cd53ca2
more env vars
tdrz Nov 18, 2025
e90f375
rename pglite main to pgl_startup
tdrz Nov 18, 2025
86cee66
submodule
tdrz Nov 18, 2025
621480f
new initdb ts bindings
Nov 20, 2025
8f0f590
builds
Nov 20, 2025
61daf27
update submodule
Nov 20, 2025
282ed01
progress standalone initdb
Nov 21, 2025
4f8c453
popen implementation
tdrz Nov 21, 2025
ea299ba
bug fix
tdrz Nov 21, 2025
57d3d47
fgets
Nov 21, 2025
7b270f4
submodule
Nov 21, 2025
813a794
improvements to fgets
tdrz Nov 21, 2025
b79df1f
progress running inidb
tdrz Nov 24, 2025
dd84f56
pglite libc
tdrz Nov 24, 2025
62765f4
trying to redirect stdin/out/err
tdrz Nov 25, 2025
a9ea2bd
fgets handling for reading the stdout of program
tdrz Nov 25, 2025
ae86b8d
progress inidb
tdrz Nov 26, 2025
0bdebdd
progress
tdrz Nov 26, 2025
36d65e2
further progress but db initialization fails because of corrupted dat…
tdrz Nov 28, 2025
aa7e91e
more initdb
tdrz Dec 1, 2025
30e698f
no comment
tdrz Dec 1, 2025
a343f3a
rewrite stdin<->stdout wiring logic
Dec 2, 2025
a87129e
no comment
tdrz Dec 4, 2025
f59dc40
cleanup initdb.ts
tdrz Dec 5, 2025
b5c6103
simplifications
tdrz Dec 6, 2025
70c9834
initdb with exit 0 - I added some flags to postgresql when running in…
tdrz Dec 7, 2025
f870dda
backup
tdrz Jan 15, 2026
4878e60
something is working
tdrz Jan 15, 2026
19faaeb
cleanup
tdrz Jan 20, 2026
6efded3
improvements
tdrz Jan 20, 2026
3d5a5dd
simple queries work!
tdrz Jan 27, 2026
69f89db
update submodule
tdrz Jan 27, 2026
d8470bd
basic tests except ones with setjmp longjmp pass
tdrz Jan 27, 2026
4e61501
more tests passing; cleanup and improvements
tdrz Jan 28, 2026
83c2f0f
update submodule
tdrz Jan 28, 2026
4af1ec3
initdb: do not throw on error
tdrz Jan 28, 2026
520648d
update submodule
tdrz Jan 28, 2026
4b5fcf2
Merge branch 'main' into tdrz/simplifyinitdb
tdrz Jan 28, 2026
b47c71b
update docs
tdrz Jan 28, 2026
e1318fd
update submodule
tdrz Jan 28, 2026
dc5edeb
update submodule
tdrz Jan 28, 2026
b3d97be
update submodule
tdrz Jan 29, 2026
f8f592b
more tests passing
tdrz Jan 29, 2026
442d5ac
update submodule
tdrz Jan 29, 2026
6a576d5
amcheck test
tdrz Jan 30, 2026
dbad558
bloom filter test fix
tdrz Jan 30, 2026
171a18a
improvements, simplifications
tdrz Feb 6, 2026
6cef05f
update submodule
tdrz Feb 6, 2026
8efecd5
more tests passing
tdrz Feb 7, 2026
1bea40a
update submodule
tdrz Feb 7, 2026
b567660
simplifications
tdrz Feb 8, 2026
8e6c237
make sure to flush
tdrz Feb 8, 2026
5e64d85
more tests passing
tdrz Feb 8, 2026
c3ed483
update submodule
tdrz Feb 8, 2026
eff4fd6
add nodefs test that reuses an already populated directory on disk
tdrz Feb 9, 2026
44731b4
close pg before test ends
tdrz Feb 9, 2026
467eb33
pglite tests pass
tdrz Feb 10, 2026
4db4346
update submodule
tdrz Feb 10, 2026
f91814d
basic browser examples work
tdrz Feb 10, 2026
1ffa35e
repl fix
tdrz Feb 10, 2026
6c36e95
all? tests pass; refactorings; allow pipelining of commands;
tdrz Feb 24, 2026
6c629e8
style
tdrz Feb 24, 2026
9ea85fb
update submodule
tdrz Feb 24, 2026
fd0d641
Merge branch 'main' of github.com:electric-sql/pglite
tdrz Feb 24, 2026
fdf18fe
merge main
tdrz Feb 24, 2026
1a897dd
pglite-socket simplifications
tdrz Feb 24, 2026
ae28531
update CI to use pglite-inidb artifacts
tdrz Feb 24, 2026
ae7143a
style
tdrz Feb 24, 2026
02c551c
deno tests fixes
tdrz Feb 24, 2026
621a382
fix pg_dump
tdrz Feb 25, 2026
bb45f50
update submodule
tdrz Feb 25, 2026
2178c82
simplifications
tdrz Feb 25, 2026
489f457
polyfill for react tests when usin jsdom
tdrz Feb 25, 2026
5fb5c1b
same polyfill for vitest
tdrz Feb 25, 2026
4a8dcbf
sorting
tdrz Feb 26, 2026
5ee5c25
exclude unsuported modules
tdrz Feb 26, 2026
6300f9f
cleanup
tdrz Feb 26, 2026
2d7ebc5
style
tdrz Feb 26, 2026
5cb4af3
update submodule
tdrz Mar 2, 2026
837b185
update submodule
tdrz Mar 2, 2026
7c2b455
update submodule
tdrz Mar 2, 2026
aef6e2c
update submodule
tdrz Mar 2, 2026
abe34b1
libicu - update submodule
tdrz Mar 8, 2026
a1dffe1
expose loadFile api call
tdrz Mar 8, 2026
651e8f4
stylecheck
tdrz Mar 8, 2026
112c19b
improvements
tdrz Mar 9, 2026
37eb2f1
Merge branch 'main' into tdrz/fe-libicu
tdrz Mar 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/pglite-initdb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release/
157 changes: 157 additions & 0 deletions packages/pglite-initdb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# @electric-sql/pglite-tools

## 0.2.19

### Patch Changes

- Updated dependencies [8785034]
- Updated dependencies [90cfee8]
- @electric-sql/pglite@0.3.14

## 0.2.18

### Patch Changes

- ad3d0d8: Updated pg_dump to use callback data exchange; built pg_dump with emscripten
- Updated dependencies [ad3d0d8]
- @electric-sql/pglite@0.3.13

## 0.2.17

### Patch Changes

- Updated dependencies [ce0e74e]
- @electric-sql/pglite@0.3.12

## 0.2.16

### Patch Changes

- Updated dependencies [9a104b9]
- @electric-sql/pglite@0.3.11

## 0.2.15

### Patch Changes

- Updated dependencies [ad765ed]
- @electric-sql/pglite@0.3.10

## 0.2.14

### Patch Changes

- e40ccad: Upgrade emsdk
- Updated dependencies [e40ccad]
- @electric-sql/pglite@0.3.9

## 0.2.13

### Patch Changes

- be677b4: fix pg_dump on Windows systems

When calling **pg_dump** on Windows system the function fails with an error as the one bellow.
❗ Notice the double drive letter
`Error: ENOENT: no such file or directory, open 'E:\C:\Users\<USERNAME>\AppData\Local\npm-cache\_npx\ba4f1959e38407b5\node_modules\@electric-sql\pglite-tools\dist\pg_dump.wasm'`

The problem is in execPgDump function at line
`const blob = await fs.readFile(bin.toString().slice(7))`
I think the intention here was to remove `file://` from the begging of the path. However this is not necesarry readFile can handle URL objects.
Moreover this will fail on Windows becase the slice creates a path like '/C:/<USERNAME>...' and the readFile function will add the extra drive letter

- Updated dependencies [f12a582]
- Updated dependencies [bd263aa]
- @electric-sql/pglite@0.3.8

## 0.2.12

### Patch Changes

- Updated dependencies [0936962]
- @electric-sql/pglite@0.3.7

## 0.2.11

### Patch Changes

- Updated dependencies [6898469]
- Updated dependencies [469be18]
- Updated dependencies [64e33c7]
- @electric-sql/pglite@0.3.6

## 0.2.10

### Patch Changes

- 8172b72: new pg_dump wasm blob
- Updated dependencies [6653899]
- Updated dependencies [5f007fc]
- @electric-sql/pglite@0.3.5

## 0.2.9

### Patch Changes

- 38a55d0: fix cjs/esm misconfigurations
- Updated dependencies [1fcaa3e]
- Updated dependencies [38a55d0]
- Updated dependencies [aac7003]
- Updated dependencies [8ca254d]
- @electric-sql/pglite@0.3.4

## 0.2.8

### Patch Changes

- Updated dependencies [ea2c7c7]
- @electric-sql/pglite@0.3.3

## 0.2.7

### Patch Changes

- Updated dependencies [e2c654b]
- @electric-sql/pglite@0.3.2

## 0.2.6

### Patch Changes

- Updated dependencies [713364e]
- @electric-sql/pglite@0.3.1

## 0.2.5

### Patch Changes

- 317fd36: Specify a peer dependency range on @electric-sql/pglite
- Updated dependencies [97e52f7]
- Updated dependencies [4356024]
- Updated dependencies [0033bc7]
- @electric-sql/pglite@0.3.0

## 0.2.4

### Patch Changes

- bbfa9f1: Restore SEARCH_PATH after pg_dump

## 0.2.3

### Patch Changes

- 8545760: pg_dump error messages set on the thrown Error
- d26e658: Run a DEALLOCATE ALL after each pg_dump to cleanup the prepared statements.

## 0.2.2

### Patch Changes

- 17c9875: add node imports to the package.json browser excludes

## 0.2.1

### Patch Changes

- 6547374: Alpha version of pg_dump support in the browser and Node using a WASM build of pg_dump
72 changes: 72 additions & 0 deletions packages/pglite-initdb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# pglite-tools

A selection of tools for working with [PGlite](https://github.com/electric-sql/pglite) databases, including pg_dump.

Install with:

```bash
npm install @electric-sql/pglite-tools
```

## `pgDump`

pg_dump is a tool for dumping a PGlite database to a SQL file, this is a WASM build of pg_dump that can be used in a browser or other JavaScript environments. You can read more about pg_dump [in the Postgres docs](https://www.postgresql.org/docs/current/app-pgdump.html).

Note: pg_dump will execute `DEALLOCATE ALL;` after each dump. Since this is running on the same (single) connection, any prepared statements that you have made before running pg_dump will be affected.

### Options

- `pg`: A PGlite instance.
- `args`: An array of arguments to pass to pg_dump - see [pg_dump docs](https://www.postgresql.org/docs/current/app-pgdump.html) for more details.
- `fileName`: The name of the file to write the dump to, defaults to `dump.sql`.

There are a number of arguments that are automatically added to the end of the command, these are:

- `--inserts` - use inserts format for the output, this ensures that the dump can be restored by simply passing the output to `pg.exec()`.
- `-j 1` - concurrency level, set to 1 as multithreading isn't supported.
- `-f /tmp/out.sql` - the output file is always written to `/tmp/out.sql` in the virtual file system.
- `-U postgres` - use the postgres user is hard coded.

### Returns

- A `File` object containing the dump.

### Caveats

- After restoring a dump, you might want to set the same search path as the initial db.

### Example

```typescript
import { PGlite } from '@electric-sql/pglite'
import { pgDump } from '@electric-sql/pglite-tools/pg_dump'

const pg = await PGlite.create()

// Create a table and insert some data
await pg.exec(`
CREATE TABLE test (
id SERIAL PRIMARY KEY,
name TEXT
);
`)
await pg.exec(`
INSERT INTO test (name) VALUES ('test');
`)

// store the current search path so it can be used in the restored db
const initialSearchPath = (await pg1.query<{ search_path: string }>('SHOW SEARCH_PATH;')).rows[0].search_path

// Dump the database to a file
const dump = await pgDump({ pg })
// Get the dump text - used for restore
const dumpContent = await dump.text()

// Create a new database
const restoredPG = await PGlite.create()
// ... and restore it using the dump
await restoredPG.exec(dumpContent)

// optional - after importing, set search path back to the initial one
await restoredPG.exec(`SET search_path TO ${initialSearchPath};`);
```
29 changes: 29 additions & 0 deletions packages/pglite-initdb/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import globals from 'globals'
import rootConfig from '../../eslint.config.js'

export default [
...rootConfig,
{
ignores: ['release/**/*', 'examples/**/*', 'dist/**/*'],
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
rules: {
...rootConfig.rules,
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['tests/targets/deno/**/*.js'],
languageOptions: {
globals: {
Deno: false,
},
},
},
]
67 changes: 67 additions & 0 deletions packages/pglite-initdb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "@electric-sql/pglite-initdb",
"version": "0.0.1",
"description": "initdb as wasm",
"author": "Electric DB Limited",
"homepage": "https://pglite.dev",
"license": "Apache-2.0",
"keywords": [
"postgres",
"sql",
"database",
"wasm",
"pglite",
"initdb"
],
"private": false,
"publishConfig": {
"access": "public"
},
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./initdb": {
"import": {
"types": "./dist/initdb.d.ts",
"default": "./dist/initdb.js"
},
"require": {
"types": "./dist/initdb.d.cts",
"default": "./dist/initdb.cjs"
}
}
},
"scripts": {
"build": "tsup",
"check:exports": "attw . --pack --profile node16",
"lint": "eslint ./src ./tests --report-unused-disable-directives --max-warnings 0",
"format": "prettier --write ./src ./tests",
"typecheck": "tsc",
"stylecheck": "pnpm lint && prettier --check ./src ./tests",
"test": "vitest",
"prepublishOnly": "pnpm check:exports"
},
"browser": {
"fs": false,
"fs/promises": false
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.1",
"@types/emscripten": "^1.41.1",
"@types/node": "^20.16.11",
"tsx": "^4.19.2",
"vitest": "^1.3.1"
}
}
Loading
Loading