Skip to content

Commit 5cfbaca

Browse files
authored
Fix prepopulatedfs README (#961)
* README for prepopulatedfs
1 parent ee5066e commit 5cfbaca

2 files changed

Lines changed: 81 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@electric-sql/pglite-prepopulatedfs': patch
3+
---
4+
5+
Improve README
Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,84 @@
11
# pglite-prepopulatedfs
22

3-
A prepopulated FS so no initdb is running on startup.
3+
A pre-populated FS that you can use instead of letting initdb run (which is the default). This can lead to faster startup times because initdb doesn't need to run.
44

55
Install with:
66

77
```bash
88
npm install @electric-sql/pglite-prepopulatedfs
99
```
10+
11+
This package contains an archive as a static asset that you can access through the `dataDir()` function.
12+
13+
:::info
14+
The prepopulated FS is created during build on our CI and therefore guaranteed to work only for the corresponding version of PGlite from which it was created. If you encounter issues, make sure this package is up to date with your PGlite version.
15+
:::
16+
17+
## Installation
18+
19+
```bash
20+
npm install @electric-sql/pglite-prepopulatedfs
21+
# or
22+
yarn add @electric-sql/pglite-prepopulatedfs
23+
# or
24+
pnpm add @electric-sql/pglite-prepopulatedfs
25+
```
26+
27+
## Usage
28+
29+
```typescript
30+
import { PGlite } from '@electric-sql/pglite'
31+
import { dataDir } from '@electric-sql/pglite-prepopulatedfs'
32+
33+
// Create a PGlite instance with the prepopulated FS
34+
const pg = await PGlite.create({
35+
loadDataDir: await dataDir(),
36+
})
37+
```
38+
39+
As an example, this is useful when you have multiple test, each with its own PGlite instance. Consider the following usage with vitest:
40+
41+
```typescript
42+
import { describe, it, expect, beforeEach } from 'vitest'
43+
import { PGlite } from '@electric-sql/pglite'
44+
import { dataDir } from '@electric-sql/pglite-prepopulatedfs'
45+
46+
describe('query and exec with different data sizes', () => {
47+
let pg: PGlite
48+
49+
beforeEach(async () => {
50+
pg = await PGlite.create({
51+
loadDataDir: await dataDir(),
52+
})
53+
54+
await pg.exec(`
55+
// setup default data
56+
`)
57+
})
58+
59+
describe('test no. 1', () => {
60+
...
61+
})
62+
63+
describe('test no. 2', () => {
64+
...
65+
})
66+
67+
// many more tests here
68+
})
69+
```
70+
71+
Although more bandwidth is needed to download the `@electric-sql/pglite-prepopulatedfs` package, the tests will run faster as PGlite doesn't need to run `initdb` for each one of them.
72+
73+
The same applies if your application needs to instantiate PGlite over and over again with a clean slate. You will initialy use more bandwidth but will save on speed in the long-run.
74+
75+
## Benchmarking
76+
77+
A simple benchmarking is done as part of our automated testing in `packages/pglite-prepopulatedfs/tests/prepopulatedfs.test.ts`.
78+
79+
Here is a sample output on an Apple M1:
80+
81+
```
82+
initdb duration: prepopulated avg (trimmed) 263.38 ms vs. classic initdb 886.29 ms.
83+
Speedup: 3.37x
84+
```

0 commit comments

Comments
 (0)