{"library":"pg-micro","title":"pg-micro: PostgreSQL-compatible Embeddable Database","description":"pg-micro is an experimental, in-process reimplementation of PostgreSQL, currently at version 0.0.5. It is built as an experimental fork of Turso, which is a full, from-scratch rewrite of SQLite in Rust. Unlike other approaches that try to compile PostgreSQL to WebAssembly or translate PostgreSQL syntax to SQLite, pg-micro directly parses the PostgreSQL language using `libpg_query` (the same parser PostgreSQL itself uses) and compiles it to SQLite bytecode for execution on Turso's engine. This approach aims to provide a fast, embeddable, single-file database that natively understands PostgreSQL syntax, targeting ephemeral, low-touch, short-lived, and small database use cases. Its key differentiators include 100% PostgreSQL syntax fidelity, direct compilation to SQLite bytecode, and a standard SQLite-compatible storage format, allowing for dual access via PostgreSQL and SQLite syntax. Release cadence is currently irregular due to its experimental nature and close ties to Turso's development cycle.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install pg-micro"],"cli":null},"imports":["import { connect } from 'pg-micro';","import { Database } from 'pg-micro';","import { type Row } from 'pg-micro';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { connect } from 'pg-micro';\n\nasync function runExample() {\n  // Connect to an in-memory database for a quick test\n  // For a file-backed database, pass a path like 'myapp.db'\n  const db = await connect(':memory:');\n\n  try {\n    // Execute DDL statement to create a table\n    await db.exec(\n      \"CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, email TEXT)\"\n    );\n    console.log('Table \"users\" created.');\n\n    // Insert data into the table using prepared statements\n    const insertStmt = db.prepare(\n      \"INSERT INTO users (name, email) VALUES ($1, $2)\"\n    );\n    await insertStmt.run('Alice', 'alice@example.com');\n    await insertStmt.run('Bob', 'bob@example.com');\n    console.log('Data inserted into \"users\" table.');\n\n    // Query data using a prepared statement and fetch all rows\n    const rows = await db.prepare(\"SELECT * FROM users\").all();\n    console.log('Fetched rows:', rows);\n    // Expected output: \n    // [\n    //   { id: 1, name: 'Alice', email: 'alice@example.com' },\n    //   { id: 2, name: 'Bob', email: 'bob@example.com' }\n    // ]\n\n  } catch (error) {\n    console.error('Database operation failed:', error);\n  } finally {\n    // Always close the database connection when done\n    await db.close();\n    console.log('Database connection closed.');\n  }\n}\n\nrunExample();","lang":"typescript","description":"Demonstrates connecting to an in-memory pg-micro database, creating a table, inserting data with prepared statements, and querying results.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}