展示 HN: LinkedQL – Postgres、MySQL、MariaDB 的实时查询
Show HN: LinkedQL – Live Queries over Postgres, MySQL, MariaDB

原始链接: https://github.com/linked-db/linked-ql

## LinkedQL:现代 SQL 客户端 LinkedQL 是一个轻量级(小于 80KB)的数据库客户端,旨在简化和统一现代应用程序的数据库交互。目前处于 Alpha 阶段,它支持 PostgreSQL、MySQL/MariaDB,以及一个名为 FlashQL 的独特内存 SQL 引擎——非常适合离线优先应用程序和测试。 它提供了一个熟悉的 `client.query()` 接口,同时引入了诸如响应式(实时查询)、简化的关系遍历、JSON 支持和 UPSERT 语句等功能。未来的功能包括模式版本控制和自动迁移。 LinkedQL 拥有跨所有支持方言的一致 API、自动模式推断,并旨在实现数据库联合和同步。虽然仍在积极开发中,核心组件正在迅速稳定,但它接受通过 GitHub 仓库中的 issue、pull request 和讨论来贡献。它专为寻求响应式、灵活和轻量级数据库层的开发者设计。

## LinkedQL:数据库实时查询 LinkedQL 是一款适用于 Postgres、MySQL 和 MariaDB 的新型 SQL 客户端,它实现了“实时查询”——结果集能够随着底层数据库的插入、更新和删除操作自动更新。这无需额外的工具,如 ORM 或 GraphQL 服务器;只需在查询中添加一个标志即可激活实时模式:`client.query('SELECT ...', { live: true })`。 核心引擎在后端运行,利用逻辑复制槽(Postgres)高效地跟踪更改。目前,Postgres 是唯一完全支持的数据库,MySQL/MariaDB 的支持正在进行中。一个前端可嵌入变体 FlashQL 允许本地数据操作并与后端引擎同步。 作者欢迎对易用性、潜在风险和生产就绪的反馈,并积极解答关于部署、身份验证(与 Postgres RLS 兼容)、扩展以及未来功能(如模式迁移和 Postgres 扩展)的问题。 更多信息,包括文档和 GitHub 仓库,请访问 [https://linked-ql.netlify.app/](https://linked-ql.netlify.app/) 和 [https://github.com/linked-db/linked-ql](https://github.com/linked-db/linked-ql)。
相关文章

原文
LinkedQL Banner

Simplify and unify your entire database layer in a single interface 🛸
LinkedQL is a database client (client.query()) for PostgreSQL and MySQL/MariaDB, but more broadly, an idea: SQL reimagined for modern apps ↗. LinkedQL solves reactivity, relationships, JSON, schemas, embedding, federation & sync, and more in under 80 KiB min | zip.


Important

🚀 LinkedQL is in active development and evolving daily. Current status = alpha.
You’re welcome to experiment, but it’s not yet suited for production apps.





LinkedQL is distributed as an npm package. Install it with:

npm install @linked-db/linked-ql

The package provides clients for all supported SQL dialects — including FlashQL, the in-memory SQL engine for local or offline use.

Import and initialize the client for your use case. You can run either fully in-memory or with a database. Here are two quick examples:

FlashQL lets you run SQL queries entirely in memory — with zero setup.

import { FlashQL } from '@linked-db/linked-ql/flashql';

const client = new FlashQL();

await client.query(`CREATE TABLE users (id INT PRIMARY KEY, name TEXT)`);
const result = await client.query(`
  INSERT INTO users (id, name) VALUES (1, 'Ada'), (2, 'Linus');
  SELECT * FROM users;
`);

console.log(result.rows);
// [{ id: 1, name: 'Ada' }, { id: 2, name: 'Linus' }]

FlashQL is ideal for:

  • Local-first and offline-first apps
  • Running SQL over runtime data
  • Testing and prototyping

Connect to your database from the list of supported dialects below. Here’s an example using PostgreSQL:

import { PGClient } from '@linked-db/linked-ql/postgres';

const client = new PGClient({
  host: 'localhost',
  port: 5432,
  user: 'postgres',
  password: 'password',
  database: 'myapp',
});

await client.connect();

const result = await client.query(`SELECT 10 AS value`);
console.log(result.rows); // [{ value: 10 }]

await client.disconnect();
Dialect Import Path Guide
PostgreSQL @linked-db/linked-ql/postgres PostgreSQL ↗
MySQL @linked-db/linked-ql/mysql MySQL ↗
MariaDB @linked-db/linked-ql/mariadb MariaDB ↗
FlashQL (In-Memory) @linked-db/linked-ql/flashql FlashQL ↗

LinkedQL maintains a unified and familiar interface across all dialects — whether remote or local. Method signatures and return values are consistent and documented in the Client API Reference ↗


Capability Description
Live Queries Turn on reactivity over any SQL query with { live: true }. No extra infrastructure required.
🔗 DeepRef Operators Traverse relationships using simple path notation (~> / <~). Insert or update nested structures using same notation.
🧩 JSON Literals Bring JSON-like clearity to your queries with LinkedQL's first-class support for JSON notation.
🪄 Upserts Do upserts with a literal UPSERT statement.
🧠 Schema Versioning (Coming soon) Get automatic schema versioning on your database: automatic snapshots and historical introspection.
💾 Edge & Offline Runtime (FlashQL) Run or embed SQL locally — in browsers, workers, or edge devices — for local-first and offline-first applications.
🌐 Federation & Sync (Alpha) Unify remote databases, REST endpoints, and local stores into a single relational graph with seamless synchronization.
Feature Description
💻 Classic client.query() Interface Same classic client interface; advanced capabalities for modern applications.
🔗 Multi-Dialect Support A universal parser that understands PostgreSQL, MySQL, MariaDB, and FlashQL — one client, many dialects.
💡 Lightweight Footprint A full reactive data layer in one compact library — under 80 KiB (min/zip).
🎯 Automatic Schema Inference No upfront schema work. LinkedQL auto-discovers your schema and stays schema-driven across complex tasks.
🪄 Diff-Based Migrations (Coming soon) Evolve schemas declaratively through change detection instead of hand-written migration scripts.

Visit the LinkedQL documentation site ↗


Component Status Note
Parser & Compiler 🟩 100% Stabilizing
Transform Engine 🟩 100% Stabilizing
Drivers (PG/MySQL) 🟩 97% Stabilizing; MySQL nearing parity
FlashQL Engine 🟩 99% Expanding
Realtime Engine 🟩 99% Stabilizing
Timeline Engine 🟨 20% Planned
Migration Wizard 10% Planned
IDE Tooling 5% Early hooks
Docs (vNext) 🟩 99% Expanding
Status Legend:

🟩 Complete | 🟨 In Progress | ⬜ Not Started

LinkedQL is in active development — and contributions are welcome!

Here’s how you can jump in:

  • Issues → Spot a bug or have a feature idea? Open an issue.
  • Pull requests → PRs are welcome for fixes, docs, or new ideas.
  • Discussions → Not sure where your idea fits? Start a discussion.

⤷ clone → install → test

git clone https://github.com/linked-db/linked-ql.git
cd linked-ql
git checkout next
npm install
npm test
  • Development happens on the next branch — be sure to switch to it as above after cloning.
  • Consider creating your feature branch from next before making changes (e.g. git checkout -b feature/my-idea).
  • Remember to npm test before submitting a PR.
  • Check the Progress section above to see where help is most needed.

MIT — see LICENSE

联系我们 contact @ memedata.com