DEV Community

Thanh Sơn Nguyễn
Thanh Sơn Nguyễn

Posted on

How can I run PostgreSQL in the browser or Node.js using in an ultra-lightweight way, similar to SQLite? PGLite!

I'm experimenting with building an embedded SQL engine for Node.js and Bun.

The idea is similar to SQLite, but the engine aims to support a large subset of PostgreSQL syntax such as:

  • joins
  • CTEs
  • window functions
  • transactions
  • JSON operators

The engine runs directly inside the application process and stores data in a local file, without requiring a PostgreSQL server.

One challenge I'm facing is how to design the SQL parser and execution layer to support PostgreSQL-style queries while still keeping the engine lightweight.

For example, SQLite has its own grammar and execution model, while PostgreSQL has a much more complex planner.

My questions are:

  1. What are the common approaches used by embedded databases to support PostgreSQL-compatible syntax?
  2. Are there open-source projects or references for implementing a PostgreSQL-like query planner in a lightweight engine?
  3. Is it realistic to support a meaningful subset of PostgreSQL features without implementing the full PostgreSQL architecture?

For context, I'm experimenting with an open-source prototype here (I'm the author):

https://github.com/pglite/pglite

Top comments (0)