@electric-sql/pglite-repl

中文文档
0.4.16发布于 2026/11/09Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2.9万

A REPL, or terminal, for use in the browser with PGlite, allowing you to have an interactive session with your WASM Postgres in the page.

原始使用文档
文档目录4 节
  1. Features:
  2. How to use with React
  3. How to use as a Web Component
  4. Development

PGlite REPL React Component

A REPL, or terminal, for use in the browser with PGlite, allowing you to have an interactive session with your WASM Postgres in the page.

Features:

  • Available as both a React.js component and a Web Components
  • CodeMirror for input editing
  • Auto complete, including table and column names from the database
  • Input history (up and down keys)
  • \d PSQL commands (via psql-describe)

How to use with React

npm install @electric-sql/pglite-repl

then to include in a page:

import { PGlite } from "@electric-sql/pglite";
import { Repl } from "@electric-sql/pglite-repl";

function MyComponent() {
  const pg = new PGlite();

  return <>
    <Repl pg={pg} />
  </>
}

The props for the <Repl> component are described by this interface:

// The theme to use, auto is auto switching based on the system
type ReplTheme = "light" | "dark" | "auto";

interface ReplProps {
  pg: PGlite;  // PGlite db instance
  border?: boolean;  // Outer border on the component, defaults to false
  lightTheme?: Extension;
  darkTheme?: Extension;
  theme?: ReplTheme;  // Defaults to "auto"
}

The lightTheme and darkTheme should be instances of a React CodeMirror theme.

How to use as a Web Component

Although the PGlite REPL is built with React, its also available as a web component for easy inclusion in any page or other framework.

<script src="https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist-webcomponent/Repl.js" type="module"></script>

<!-- Include the Repl web component in your page -->
<pglite-repl id="repl"></pglite-repl>

<script type="module">
  import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js";

  // Create a PGlite instance
  const pg = new PGlite();

  // Retrieve the Repl element
  const repl = document.getElementById('repl');

  // REPL to your PGlite instance
  repl.pg = pg;
</script>

Development

Checkout this repo and from package dir:

# Install deps
pnpm install

# Run dev server
pnpm dev
# then open a browser to the url shown

# Build the lib
pnpm build

版本与发布记录

@electric-sql/pglite-repl 共发布 62 个版本,首次发布于 2024/07/23;过去 12 个月发布了 26 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.16latest2026/11/094 天前
0.4.152026/11/0310 天前
0.4.142026/10/3113 天前
0.4.132026/10/2816 天前
0.4.122026/10/2618 天前
0.4.112026/10/2123 天前

其他发布通道:next → 1.0.0-next.1。

关于 @electric-sql/pglite-repl 的常见问题

@electric-sql/pglite-repl 是什么?

A REPL, or terminal, for use in the browser with PGlite, allowing you to have an interactive session with your WASM Postgres in the page.

如何安装 @electric-sql/pglite-repl?

在项目目录运行 npm install @electric-sql/pglite-repl,或使用 pnpm add / yarn add / bun add。

@electric-sql/pglite-repl 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@electric-sql/pglite-repl 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@electric-sql/pglite-repl 可以商用吗?

@electric-sql/pglite-repl 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@electric-sql/pglite-repl 的下载量有多少?

根据 npm 官方下载统计,@electric-sql/pglite-repl 在 2026/10/14 – 2026/11/12 这 30 天内被下载 28,771 次,日均约 959 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@electric-sql/pglite-repl 还在维护吗?

最新版本 0.4.16 发布于 2026/11/09(4 天前);至今共发布 62 个版本,其中过去 12 个月发布了 26 个;首次发布于 2024/07/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。