pglite/packages/pglite-prepopulatedfs at main · electric-sql/pglite · GitHub
//files/disambiguate" data-turbo-transient="true" />
Skip to content
Search or jump to...
Search code, repositories, users, issues, pull requests...
-->
Search
Clear
Search syntax tips
Provide feedback
--><br>We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contacted
Cancel
Submit feedback
Saved searches
Use saved searches to filter your results more quickly
-->
Name
Query
To see all available qualifiers, see our documentation.
Cancel
Create saved search
Sign in
//files/disambiguate;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up
Appearance settings
Resetting focus
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
electric-sql
pglite
Public
Notifications<br>You must be signed in to change notification settings
Fork<br>388
Star<br>15.2k
FilesExpand file tree
main
/pglite-prepopulatedfs<br>Copy path
Directory actions
More options<br>More options
Directory actions
More options<br>More options
Latest commit
History<br>History<br>History
main
/pglite-prepopulatedfs
Top
Folders and files<br>NameNameLast commit message<br>Last commit date<br>parent directory<br>..<br>scripts
scripts
src
src
tests
tests
.gitignore
.gitignore
CHANGELOG.md
CHANGELOG.md
README.md
README.md
eslint.config.js
eslint.config.js
package.json
package.json
tsconfig.json
tsconfig.json
tsup.config.ts
tsup.config.ts
vitest.config.ts
vitest.config.ts
View all files
README.md<br>Outline<br>pglite-prepopulatedfs
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.
Install with:
npm install @electric-sql/pglite-prepopulatedfs
This package contains an archive as a static asset that you can access through the dataDir() function.
:::info<br>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.<br>:::
Installation
npm install @electric-sql/pglite-prepopulatedfs<br># or<br>yarn add @electric-sql/pglite-prepopulatedfs<br># or<br>pnpm add @electric-sql/pglite-prepopulatedfs
Usage
import { PGlite } from '@electric-sql/pglite'<br>import { dataDir } from '@electric-sql/pglite-prepopulatedfs'
// Create a PGlite instance with the prepopulated FS<br>const pg = await PGlite.create({<br>loadDataDir: await dataDir(),<br>})
As an example, this is useful when you have multiple test, each with its own PGlite instance. Consider the following usage with vitest:
let pg: PGlite
beforeEach(async () => {<br>pg = await PGlite.create({<br>loadDataDir: await dataDir(),<br>})
await pg.exec(`<br>// setup default data<br>`)<br>})
describe('test no. 1', () => {<br>...<br>})
describe('test no. 2', () => {<br>...<br>})
// many more tests here<br>})">import { describe, it, expect, beforeEach } from 'vitest'<br>import { PGlite } from '@electric-sql/pglite'<br>import { dataDir } from '@electric-sql/pglite-prepopulatedfs'
describe('query and exec with different data sizes', () => {<br>let pg: PGlite
beforeEach(async () => {<br>pg = await PGlite.create({<br>loadDataDir: await dataDir(),<br>})
await pg.exec(`<br>// setup default data<br>`)<br>})
describe('test no. 1', () => {<br>...<br>})
describe('test no. 2', () => {<br>...<br>})
// many more tests here<br>})
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.
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.
Benchmarking
A simple benchmarking is done as part of our automated testing in packages/pglite-prepopulatedfs/tests/prepopulatedfs.test.ts.
Here is a sample output on an Apple M1:
initdb duration: prepopulated avg (trimmed) 263.38 ms vs. classic initdb 886.29 ms.<br>Speedup: 3.37x
You can’t perform that action at this time.