You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.jsand Bun, with no need to install any other dependencies. It is only 3mb gzipped and has support for many Postgres extensions, including [pgvector](https://github.com/pgvector/pgvector).
36
+
PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js, Bun and Deno, with no need to install any other dependencies. It is only 3mb gzipped and has support for many Postgres extensions, including [pgvector](https://github.com/pgvector/pgvector).
37
37
38
38
```javascript
39
39
import { PGlite } from"@electric-sql/pglite";
@@ -43,7 +43,7 @@ await db.query("select 'Hello world' as message;");
43
43
// -> { rows: [ { message: "Hello world" } ] }
44
44
```
45
45
46
-
It can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun) or indexedDB (Browser).
46
+
It can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun/Deno) or indexedDB (Browser).
47
47
48
48
Unlike previous "Postgres in the browser" projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM.
49
49
@@ -76,14 +76,28 @@ or to persist the database to indexedDB:
76
76
constdb=newPGlite("idb://my-pgdata");
77
77
```
78
78
79
-
## Node/Bun
79
+
## Node/Bun/Deno
80
80
81
81
Install into your project:
82
82
83
+
**NodeJS**
84
+
83
85
```bash
84
86
npm install @electric-sql/pglite
85
87
```
86
88
89
+
**Bun**
90
+
91
+
```bash
92
+
bun install @electric-sql/pglite
93
+
```
94
+
95
+
**Deno**
96
+
97
+
```bash
98
+
deno add npm:@electric-sql/pglite
99
+
```
100
+
87
101
To use the in-memory Postgres:
88
102
89
103
```javascript
@@ -110,20 +124,51 @@ Fortunately, PostgreSQL includes a "single user mode" primarily intended for com
110
124
111
125
- PGlite is single user/connection.
112
126
113
-
## How to contribute
127
+
## How to build PGlite and contribute
128
+
129
+
The build process of PGlite is split into two parts:
130
+
131
+
1. Building the Postgres WASM module.
132
+
2. Building the PGlite client library and other TypeScript packages.
114
133
115
-
You will need [pnpm](https://pnpm.io/)installed, and a recent version of Node.js (v20 and above).
134
+
Docker is required to build the WASM module, along with Node (v20 or above) and [pnpm](https://pnpm.io/)for package management and building the TypeScript packages.
116
135
117
-
You will also need the Postgres WASM build files, which you download from a comment under the most recently merged PR, labeled as _interim build files_, and place them under `packages/pglite/release`. These are necessary to build PGlite and the dependent workspace projects. We plan to enable a local build in the future to streamline this step.
136
+
To start checkout the repository and install dependencies:
118
137
119
-
Once the requirements are met, you can install dependencies and build the workspace projects:
120
138
```bash
139
+
git clone https://github.com/electric-sql/pglite
140
+
cd pglite
121
141
pnpm install
122
-
pnpm build
142
+
```
143
+
144
+
To build everything, we have the convenient `pnpm build:all` command in the root of the repository. This command will:
145
+
146
+
1. Use Docker to build the Postgres WASM module. The artifacts from this are then copied to `/packages/pglite/release`.
147
+
2. Build the PGlite client library and other TypeScript packages.
148
+
149
+
To _only_ build the Postgres WASM module (i.e. point 1 above), run
150
+
151
+
```bash
152
+
pnpm wasm:build
153
+
```
154
+
155
+
If you don't want to build the WASM module and assorted WASM binaries from scratch, you can download them from a comment under the most recently merged PR, labeled as _interim build files_, and place them under `packages/pglite/release`.
156
+
157
+
To build all TypeScript packages (i.e. point 2 of the above), run:
158
+
159
+
```bash
160
+
pnpm ts:build
123
161
```
124
162
125
163
This will build all packages in the correct order based on their dependency relationships. You can now develop any individual package using the `build` and `test` scripts, as well as the `stylecheck` and `typecheck` scripts to ensure style and type validity.
126
164
165
+
Or alternatively to build a single package, move into the package directory and run:
166
+
167
+
```bash
168
+
cd packages/pglite
169
+
pnpm build
170
+
```
171
+
127
172
When ready to open a PR, run the following command at the root of the repository:
0 commit comments