[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-74693":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":13,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":18,"compositeScore":19,"rankGlobal":9,"rankLanguage":9,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":9,"pushedAt":9,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":15,"starSnapshotCount":15,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},74693,"pgmicro","glommer\u002Fpgmicro","glommer","An in-process reimplementation of PostgreSQL, backed by a SQLite-compatible storage engine",null,"Rust",1078,22,9,1,0,5,40,15,70.59,"MIT License",false,"master",true,[],"2026-06-12 04:01:15","\u003Cp align=\"center\">\n  \u003Cimg src=\"pgmicro-logo.png\" alt=\"pgmicro\" width=\"600\"\u002F>\n\u003C\u002Fp>\n\n# pgmicro\n\nAn in-process reimplementation of PostgreSQL, backed by a SQLite-compatible storage engine.\n\npgmicro is built as an experimental fork of [Turso](https:\u002F\u002Fgithub.com\u002Ftursodatabase\u002Fturso) — a full from-scratch rewrite of SQLite in Rust — with PostgreSQL added as a native dialect. The result is a fast, embeddable, single-file database that speaks PostgreSQL.\n\n## Why?\n\nAI agents are driving an explosion of databases. Many of them are ephemeral, low-touch, short-lived, and small — a scratch database for a task, a session store that lives for minutes, a per-user sandbox.\n\nSQLite has traditionally been king in these environments, and it's easy to see why: it's just a file (or even in-memory), no server to manage, no ports to configure. But many developers prefer PostgreSQL — whether out of familiarity, taste, or because PostgreSQL is legitimately more powerful in areas like its type system, JSON operators, and query capabilities.\n\nOther approaches to bring PostgreSQL in-process try to compile PostgreSQL itself to WebAssembly. But PostgreSQL's architecture — particularly its process-per-connection model, shared memory assumptions, and reliance on a full OS environment — makes this fundamentally constrained. You end up fighting the architecture rather than benefiting from it.\n\npgmicro takes a different path entirely.\n\n## How is pgmicro different?\n\npgmicro does not translate PostgreSQL to SQLite syntax. It does not embed or compile PostgreSQL. Instead, it **parses the PostgreSQL language and compiles it directly to SQLite bytecode**.\n\nHere's how it works:\n\n```\n                        pgmicro architecture\n                        ====================\n\n  PostgreSQL SQL                          SQLite SQL\n       │                                      │\n       ▼                                      ▼\n ┌─────────────┐                       ┌───────────-──┐\n │ libpg_query │                       │ Turso Parser │\n │ (PG parser) │                       │ (SQLite)     │\n └─────┬───────┘                       └──────┬─────-─┘\n       │ PG parse tree                        │ SQLite AST\n       ▼                                      │\n ┌─────────────┐                              │\n │  Translator │──── Turso AST ──────────────►│\n │ (parser_pg) │                              │\n └─────────────┘                              ▼\n                                    ┌──────────────────┐\n                                    │  Turso Compiler  │\n                                    │ (translate\u002F*.rs) │\n                                    └────────┬─────────┘\n                                             │ VDBE bytecode\n                                             ▼\n                                    ┌──────────────────┐\n                                    │  Bytecode Engine │\n                                    │  (vdbe\u002F*.rs)     │\n                                    └────────┬─────────┘\n                                             │\n                                             ▼\n                                    ┌────────────────────┐\n                                    │  SQLite Storage    │\n                                    │ (B-tree, WAL, etc) │\n                                    └────────────────────┘\n```\n\nThe key pieces:\n\n- **PostgreSQL parser**: We use [`libpg_query`](https:\u002F\u002Fgithub.com\u002Fpganalyze\u002Flibpg_query) (via the [`pg_query`](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fpg_query) Rust crate), which extracts PostgreSQL's *actual* parser from the PostgreSQL source code. This means pgmicro parses PostgreSQL syntax with 100% fidelity — it's the same parser PostgreSQL itself uses. We did not write a PostgreSQL parser.\n\n- **Translator** (`parser_pg\u002F`): A translation layer that converts the PostgreSQL parse tree into Turso's internal AST. This handles the mapping of PostgreSQL-specific syntax (e.g., `$$dollar quoting$$`, `::` casts, `SERIAL` types, PostgreSQL-style `CREATE TABLE`) into the representation that Turso's compiler understands.\n\n- **Turso engine**: The full [Turso](https:\u002F\u002Fgithub.com\u002Ftursodatabase\u002Fturso) database engine — a complete, from-scratch reimplementation of SQLite in Rust. It compiles the AST to bytecode and executes it against a SQLite-compatible B-tree storage format. Your data lives in a standard `.db` file.\n\n- **PostgreSQL catalog**: Virtual tables (`pg_class`, `pg_attribute`, `pg_type`, `pg_namespace`, etc.) that expose schema metadata in the way PostgreSQL tools expect, enabling compatibility with `psql` and other PostgreSQL clients.\n\n- **Dialect switching**: Turso supports dynamic dialect switching at the connection level. A single database can be accessed via both PostgreSQL and SQLite syntax — useful for tooling, migration, and interop.\n\n## Installation\n\n### CLI\n\nRun directly with npx (no install needed):\n\n```\nnpx pg-micro\n```\n\nOr install globally:\n\n```\nnpm install -g pg-micro\npg-micro myapp.db\n```\n\n### JavaScript\u002FTypeScript SDK\n\n```\nnpm install pg-micro\n```\n\n```javascript\nimport { connect } from \"pg-micro\";\n\nconst db = await connect(\":memory:\");\nawait db.exec(\"CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, email TEXT)\");\nawait db.exec(\"INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')\");\nawait db.exec(\"INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com')\");\n\nconst rows = await db.prepare(\"SELECT * FROM users\").all();\nconsole.log(rows);\n\u002F\u002F [\n\u002F\u002F   { id: 1, name: 'Alice', email: 'alice@example.com' },\n\u002F\u002F   { id: 2, name: 'Bob', email: 'bob@example.com' }\n\u002F\u002F ]\n\nawait db.close();\n```\n\nThe SDK API is compatible with [`@tursodatabase\u002Fdatabase`](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@tursodatabase\u002Fdatabase).\n\n## Examples\n\n### In-memory database\n\n```\n$ pgmicro\npgmicro v0.6.0-pre.7\nType \\? for help, \\q to quit.\nConnected to a transient in-memory database.\n\npgmicro> CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, email TEXT);\npgmicro> INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');\npgmicro> INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com');\npgmicro> SELECT * FROM users;\n┌────┬───────┬───────────────────┐\n│ id │ name  │ email             │\n├────┼───────┼───────────────────┤\n│  1 │ Alice │ alice@example.com │\n├────┼───────┼───────────────────┤\n│  2 │ Bob   │ bob@example.com   │\n└────┴───────┴───────────────────┘\n\npgmicro> \\dt\n+-------+\n| Table |\n+=======+\n| users |\n+-------+\n\npgmicro> \\d users\nTable: users\n+--------+------+----------+---------+\n| Column | Type | Nullable | Default |\n+========+======+==========+=========+\n| id     | int4 | NULL     | YES     |\n+--------+------+----------+---------+\n| name   | text | NULL     |         |\n+--------+------+----------+---------+\n| email  | text | NULL     |         |\n+--------+------+----------+---------+\n```\n\n### File-backed database\n\n```\n$ pgmicro myapp.db\npgmicro v0.6.0-pre.7\nType \\? for help, \\q to quit.\n\npgmicro> CREATE TABLE events (id INT, payload TEXT, ts TEXT DEFAULT CURRENT_TIMESTAMP);\npgmicro> INSERT INTO events (id, payload) VALUES (1, 'user.signup');\npgmicro> \\q\n\n$ file myapp.db\nmyapp.db: SQLite 3.x database\n\n$ pgmicro myapp.db\npgmicro> SELECT * FROM events;\n┌────┬─────────────┬─────────────────────┐\n│ id │ payload     │ ts                  │\n├────┼─────────────┼─────────────────────┤\n│  1 │ user.signup │ 2025-03-26 12:00:00 │\n└────┴─────────────┴─────────────────────┘\n```\n\nThe underlying file is a standard SQLite database — you can inspect it with any SQLite tool.\n\n### Server mode with psql\n\nAlthough I expect most of the value of this to be derived from uses in-memory or in-file, pgmicro includes a PostgreSQL wire protocol server, so standard PostgreSQL clients can connect. It is a very simple server at this point, but very helpful to make sure that tools work:\n\n```\n$ pgmicro :memory: --server 127.0.0.1:5432\nPostgreSQL server listening on 127.0.0.1:5432 (database: :memory:)\n```\n\nIn another terminal:\n\n```\n$ psql -h 127.0.0.1 -p 5432 -U turso -d main\nmain=> CREATE TABLE users (id INT, name TEXT);\nCREATE TABLE\nmain=> INSERT INTO users VALUES (1, 'Alice');\nINSERT 0 1\nmain=> INSERT INTO users VALUES (2, 'Bob');\nINSERT 0 1\nmain=> SELECT * FROM users;\n id | name\n----+-------\n  1 | Alice\n  2 | Bob\n(2 rows)\n\nmain=> \\dt\n         List of tables\n Schema | Name  | Type  | Owner\n--------+-------+-------+-------\n public | users | table | turso\n(1 row)\n```\n\n## Status\n\nThis is a heavily experimental project. I want to see how far I can take this. At this point, no guarantees are made about stability, compatibility, or completeness.\n\nThis project is not officially affiliated with Turso, although I am the founder of Turso.\n\n## Contributing\n\nContributions are welcome. pgmicro is fully licensed under the MIT license (same as Turso).\n\nSome key guidelines:\n\n**Build on Turso, don't hack around it.** I believe this project has potential to achieve very good results, which means the right approach is often to add native support in Turso's core first — with efficient bytecode — and then have pgmicro wrap it. A good example is the type system: while it would be tempting to just map PostgreSQL types to SQLite types at translation time, we instead [added support for custom types in Turso](https:\u002F\u002Fgithub.com\u002Ftursodatabase\u002Fturso\u002Fpull\u002F5729) and implemented PostgreSQL types on top of that. The result is cleaner, faster, and more correct.\n\n**Minimize changes to the Turso core.** Turso is under heavy development, so touching core code will lead to frequent merge conflicts. Some of it is unavoidable (like the pragmas to set the dialect), but significant code changes in the Turso core are a signal that perhaps this is a feature that should be proposed and pushed to Turso first.\n\n**AI is encouraged, but do the work.** Prompting an LLM and sending the result without review, testing, or understanding will lead me to stop paying attention to your contributions. See my thoughts on this: [What happens with OSS in the age of AI](https:\u002F\u002Fturso.tech\u002Fblog\u002Fwhat-happens-with-oss-in-the-age-of-ai).\n","pgmicro 是一个基于 SQLite 兼容存储引擎的 PostgreSQL 进程内重新实现。它使用 Rust 语言构建，核心功能包括直接将 PostgreSQL 语法解析并编译为 SQLite 字节码，从而提供了一个快速、可嵌入且单文件形式的数据库解决方案，支持完整的 PostgreSQL 方言。该项目适用于需要轻量级、短期或低维护成本数据库的应用场景，如临时任务数据库、会话存储或用户沙盒环境。相比其他尝试将 PostgreSQL 移植到 WebAssembly 的方案，pgmicro 通过采用不同的技术路径，避免了与原架构不兼容的问题，使得开发者能够在不牺牲性能的情况下享受 PostgreSQL 的强大特性。",2,"2026-06-11 03:50:28","high_star"]