Skip to content

Latest commit

 

History

History
104 lines (79 loc) · 2.47 KB

File metadata and controls

104 lines (79 loc) · 2.47 KB

Getting Started

Requirements

Requirement Version
Node.js 20 or later
.NET Runtime 8.0 or later
Prettier 3.x

The plugin embeds a compiled C# layer that calls the PostgreSQL parser (libpg_query) via a native shared library. The .NET 8 runtime must be installed on the machine that runs Prettier — it is not bundled inside the npm package.

Download .NET 8: https://dotnet.microsoft.com/download/dotnet/8.0


Installation

npm install --save-dev prettier prettier-plugin-postgresql

Basic configuration

// prettier.config.js
export default {
  plugins: ['prettier-plugin-postgresql'],
  overrides: [
    {
      files: ['*.sql', '*.pgsql'],
      options: {
        parser: 'pgsql',
      },
    },
  ],
};

VS Code

  1. Install the Prettier - Code formatter extension.
  2. Add to .vscode/settings.json:
{
  "[sql]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.formatOnSave": true
  }
}

Updating the plugin: The .NET DLL is loaded into VS Code's extension host process while VS Code is running. On Windows this creates a hard file lock — npm install will fail to overwrite the DLL if VS Code is open. On macOS and Linux the lock is softer but VS Code will keep running the old version anyway.

Close VS Code first, then run npm install, then reopen VS Code.


Verification

After installation, format a test file to confirm the plugin is working:

echo "SELECT id,title FROM books WHERE price<50 ORDER BY price;" | npx prettier --parser pgsql

Expected output:

select
  id,
  title
from books
where price < 50
order by price;

Building from Source

git clone https://github.com/your-org/prettier-plugin-postgresql
cd prettier-plugin-postgresql
npm install
npm run build
npm test

Build scripts

Script Description
npm run build Full build: dotnet publish + copy native + tsc
npm run build:dotnet C# layer only (dotnet msbuild + copy native lib)
npm run build:ts TypeScript only (tsc)
npm run build:ts:watch Watch mode for TypeScript
npm test Run Vitest snapshot tests
npm run test:watch Watch mode for tests

The dotnet build step publishes PgScriptDom.dll and copies the platform-specific libpg_query native library into bin/dotnet/ so the runtime can find it via DllImport probing.