stable

sql

Dialect-aware SQL migration dump for Postgres / MySQL / SQLite. Export-only.

@noy-db/as-sql · pnpm add @noy-db/as-sql Decrypts records and emits dialect-aware CREATE TABLE + INSERT statements.

What it does

as-sql is a one-way migration helper — it emits a SQL dump you can pipe straight into psql -f, mysql <, or sqlite3 <, with schema+data, schema-only, or data-only modes across Postgres, MySQL, and SQLite dialects. It is export-only: there is no reader, because SQL-dialect parsing back into a diff is a tar pit (each dialect serializes types differently with no canonical AST).

Usage

import { asSql } from '@noy-db/as-sql'

const sql = await vault.export(asSql({ dialect: 'postgres', mode: 'schema+data' }), {
  collections: ['invoices'],
})
// CREATE TABLE invoices (...);
// INSERT INTO invoices (...) VALUES (...);

See also