Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/slimy-buckets-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Restore process.exitCode
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<source media="(prefers-color-scheme: light)"
srcset="https://raw.githubusercontent.com/electric-sql/pglite/main/docs/public/img/brand/logo-light.svg"
/>
<img alt="ElectricSQL logo"
<img alt="PGlite logo"
src="https://raw.githubusercontent.com/electric-sql/pglite/main/docs/public/img/brand/logo-light.svg"
/>
</picture>
</a>
</p>

<p align="center">
<a href="https://pglite.dev">PGlite</a> - the WASM build of Postgres from <a href="https://electric-sql.com" target="_blank">ElectricSQL</a>.<br>
<a href="https://pglite.dev">PGlite</a> - the WASM build of Postgres from <a href="https://electric.ax" target="_blank">Electric</a>.<br>
Build reactive, realtime, local-first apps directly on Postgres.
<p>

Expand Down
6 changes: 3 additions & 3 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default defineConfig({
{ text: 'About', link: '/docs/about' },
{ text: 'Docs', link: '/docs/' },
{ text: 'REPL', link: '/repl/' },
{ text: 'ElectricSQL', link: 'https://www.electric-sql.com' },
{ text: 'Electric', link: 'https://www.electric.ax' },
{
text: 'GitHub',
link: 'https://github.com/electric-sql/pglite',
Expand Down Expand Up @@ -119,7 +119,7 @@ export default defineConfig({
{ text: 'Multi-tab Worker', link: '/docs/multi-tab-worker' },
{ text: 'REPL Component', link: '/docs/repl' },
{ text: 'ORMs & Query Builders', link: '/docs/orm-support' },
{ text: 'Sync using ElectricSQL', link: '/docs/sync' },
{ text: 'Sync using Postgres Sync', link: '/docs/sync' },
{ text: 'PGlite Socket', link: '/docs/pglite-socket' },
{
text: 'PGlite tools',
Expand Down Expand Up @@ -159,7 +159,7 @@ export default defineConfig({
footer: {
message:
'Dual-licensed under <a href="https://github.com/electric-sql/pglite/blob/main/LICENSE">Apache 2.0</a> and the <a href="https://github.com/electric-sql/pglite/blob/main/POSTGRES-LICENSE">PostgreSQL License</a>',
copyright: '© <a href="https://electric-sql.com/">ElectricSQL</a>',
copyright: '© <a href="https://electric.ax/">Electric</a>',
},
search: {
provider: 'local',
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It can be used as an ephemeral in-memory database, or with persistence either to

Unlike previous "Postgres in the browser" projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM.

It's being developed by [ElectricSQL](https://electric-sql.com/) for our use case of embedding into applications, either locally or at the edge, allowing users to sync a subset of their server-side Postgres database.
It's being developed by [Electric](https://electric.ax/) for our use case of embedding into applications, either locally or at the edge, allowing users to sync a subset of their server-side Postgres database.

However, there are many more use cases for PGlite beyond its use as an embedded application database:

Expand Down
10 changes: 5 additions & 5 deletions docs/docs/sync.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sync using ElectricSQL
# Sync using Electric

At [ElectricSQL](https://electric-sql.com/) we are building a sync engine to enable realtime partial replication from Postgres to any other datastore, be it a JavaScript framework state store in a webapp, a database at the edge, or an embedded database in the mobile application.
At [Electric](https://electric.ax/) we are building a sync engine to enable realtime partial replication from Postgres to any other datastore, be it a JavaScript framework state store in a webapp, a database at the edge, or an embedded database in the mobile application.

To accompany Electric, we are developing a sync extension for PGlite that will enable you to synchronise a remote Postgres with PGlite.

Expand Down Expand Up @@ -113,12 +113,12 @@ The `electricSync` plugin can be given some configuration options to allow custo

## syncShapeToTable API

The `syncShapeToTable` is a relatively thin wrapper around the Electric [ShapeStream API](https://next.electric-sql.com/api/clients/typescript#shapestream) designed to do the minimal required to sync a shape _into_ a table.
The `syncShapeToTable` is a relatively thin wrapper around the Electric [ShapeStream API](https://electric.ax/docs/api/clients/typescript#shapestream) designed to do the minimal required to sync a shape _into_ a table.

It takes the following options as an object:

- `shape: ShapeStreamOptions`<br>
The shape stream specification to sync, described by the Electric [ShapeStream API](https://electric-sql.com/docs/api/clients/typescript#shapestream) options, see the [ShapeStream API](https://electric-sql.com/docs/api/clients/typescript#options) for more details.
The shape stream specification to sync, described by the Electric [ShapeStream API](https://electric.ax/docs/api/clients/typescript#shapestream) options, see the [ShapeStream API](https://electric.ax/docs/api/clients/typescript#options) for more details.

- `table: string`<br>
The name of the table to sync into.
Expand Down Expand Up @@ -169,7 +169,7 @@ The returned `shape` object from the `syncShapeToTable` call has the following m
Unsubscribe from the shape. Note that this does not clear the state that has been synced into the table.

- `stream: ShapeStream`<br>
The underlying `ShapeStream` instance, see the [ShapeStream API](https://electric-sql.com/docs/api/clients/typescript#shapestream) for more details.
The underlying `ShapeStream` instance, see the [ShapeStream API](https://electric.ax/docs/api/clients/typescript#shapestream) for more details.

## syncShapesToTables API

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function renderGitHub() {
if (!countEl) {
countEl = document.createElement('span')
countEl.classList.add('count')
countEl.innerText = `(${toShortDecimal(initialStarCount)})`;
countEl.innerText = `(${toShortDecimal(initialStarCount)})`;

const icon = document.createElement('span')
icon.classList.add('vpi-social-github')
Expand Down
4 changes: 2 additions & 2 deletions packages/pglite-react/test/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,11 @@ function testLiveQuery(queryHook: 'useLiveQuery' | 'useLiveIncrementalQuery') {
)
// Trigger an update
await db.exec(
`INSERT INTO pattern_matching (statement) VALUES ('ElectricSQL + pglite = <3');`,
`INSERT INTO pattern_matching (statement) VALUES ('Electric + pglite = <3');`,
)
await waitFor(() =>
expect(result.current?.rows[0].statement).toBe(
'ElectricSQL + pglite = <3',
'Electric + pglite = <3',
),
)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/pglite-sync/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PGlite ElectricSQL Sync Plugin
# PGlite Postgres Sync Plugin

A [sync plugin](https://pglite.dev/docs/sync) for [PGlite](https://pglite.dev/) using [ElectricSQL](https://electric-sql.com/). Full documentation is available at [pglite.dev/docs/sync](https://pglite.dev/docs/sync).
A [sync plugin](https://pglite.dev/docs/sync) for [PGlite](https://pglite.dev/) using [Electric](https://electric.ax/). Full documentation is available at [pglite.dev/docs/sync](https://pglite.dev/docs/sync).

To install:

Expand Down
2 changes: 1 addition & 1 deletion packages/pglite-sync/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@electric-sql/pglite-sync",
"version": "0.5.5",
"description": "ElectricSQL Sync for PGlite",
"description": "Postgres Sync for PGlite",
"type": "module",
"private": false,
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite-sync/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export type PGliteWithSync = PGliteInterface & {

export function electricSync(options?: ElectricSyncOptions) {
return {
name: 'ElectricSQL Sync',
name: 'Postgres Sync',
setup: async (pg: PGliteInterface) => {
const { namespaceObj, close } = await createPlugin(pg, options)
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/pglite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<source media="(prefers-color-scheme: light)"
srcset="https://raw.githubusercontent.com/electric-sql/pglite/main/docs/public/img/brand/logo-light.svg"
/>
<img alt="ElectricSQL logo"
<img alt="PGlite logo"
src="https://raw.githubusercontent.com/electric-sql/pglite/main/docs/public/img/brand/logo-light.svg"
/>
</picture>
</a>
</p>

<p align="center">
<a href="https://pglite.dev">PGlite</a> - the WASM build of Postgres from <a href="https://electric-sql.com" target="_blank">ElectricSQL</a>.<br>
<a href="https://pglite.dev">PGlite</a> - the WASM build of Postgres from <a href="https://electric.ax" target="_blank">Electric</a>.<br>
Build reactive, realtime, local-first apps directly on Postgres.
<p>

Expand Down
20 changes: 20 additions & 0 deletions packages/pglite/src/pglite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ export class PGlite
* @returns A promise that resolves when the database is ready
*/
async #init(options: PGliteOptions) {
// PGlite modifies process.exitCode when it does exit(XX)
// we need to restore the previous value
let prevExitCode = undefined
if (globalThis.process?.env) {
prevExitCode = process.exitCode
}

if (options.fs) {
this.fs = options.fs
} else {
Expand Down Expand Up @@ -567,6 +574,10 @@ export class PGlite
await initFn()
}
}

if (globalThis.process?.env) {
process.exitCode = prevExitCode
}
}

#onRuntimeInitialized(mod: PostgresMod) {
Expand Down Expand Up @@ -828,6 +839,12 @@ export class PGlite
return result
}

let prevExitCode = undefined
if (globalThis.process?.env) {
// store current process exit code
prevExitCode = process.exitCode
}

// execute the message
try {
// a single message might contain multiple batched queries
Expand Down Expand Up @@ -858,6 +875,9 @@ export class PGlite
} finally {
mod._PostgresSendReadyForQueryIfNecessary()
mod._pgl_pq_flush()
if (globalThis.process?.env) {
process.exitCode = prevExitCode
}
}

this.#outputData = []
Expand Down
14 changes: 14 additions & 0 deletions packages/pglite/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,5 +701,19 @@ await testEsmCjsAndDTC(async (importType) => {
)
expect(databaseAndRole[0].rows[0].setting).toEqual(dateTime)
})

it('restores process.exitCode', async () => {
const origExitCode = process.exitCode
const db = await PGlite.create()
expect(process.exitCode).toEqual(origExitCode)

await db.exec(`
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
name TEXT
);`)

expect(process.exitCode).toEqual(origExitCode)
})
})
})
2 changes: 1 addition & 1 deletion postgres-pglite
Loading