npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lebedevna/prettier-plugin-sql

v0.3.2

Published

Prettier plugin for PostgreSQL DDL formatting.

Readme

@lebedevna/prettier-plugin-sql

Prettier plugin for formatting a focused subset of PostgreSQL DDL.

The plugin is intentionally narrow. It formats supported statements into the house style shown in example.sql and leaves everything else structurally unchanged.

Install

npm install --save-dev prettier @lebedevna/prettier-plugin-sql

Peer requirement: prettier@^3.

Usage

Prettier config

// prettier.config.js
import sqlPlugin from "@lebedevna/prettier-plugin-sql";

export default {
  plugins: [sqlPlugin],
};

If you use JSON config, reference the package name:

{
  "plugins": ["@lebedevna/prettier-plugin-sql"]
}

Format SQL files

npx prettier --write schema.sql

The plugin registers the sql parser for .sql files.

Example

Input:

create table job(
  job_id integer generated always as identity,
  created_at timestamp not null,
  is_active boolean not null default true,
  constraint status_fk foreign key(status_id) references dict_job_status(id)
) partition by range(created_at)

Output:

CREATE TABLE job (
    job_id     integer   GENERATED ALWAYS AS IDENTITY,
    created_at timestamp NOT NULL,
    is_active  boolean   NOT NULL DEFAULT true,
    CONSTRAINT status_fk FOREIGN KEY (status_id) REFERENCES dict_job_status (id)
) PARTITION BY RANGE (created_at);

Supported Statements

  • CREATE DOMAIN ... AS ...
  • CREATE TYPE ... AS ENUM (...)
  • CREATE TABLE ...

Supported Table Formatting

For supported CREATE TABLE statements, the formatter currently handles:

  • column definitions
  • quoted identifiers
  • table constraints such as PRIMARY KEY, UNIQUE, and FOREIGN KEY ... REFERENCES ...
  • GENERATED ALWAYS AS IDENTITY
  • DEFAULT ...
  • explicit NULL and NOT NULL
  • inline -- comments placed above columns or constraints
  • PARTITION BY RANGE (...)

Behavior

  • Uppercases supported structural keywords while preserving identifier case and string literals
  • Aligns column names, data types, and nullability within a table
  • Reorders nullability ahead of trailing clauses such as DEFAULT
  • Preserves unsupported statements instead of trying to restyle them
  • Normalizes the final output to include a trailing semicolon and newline
  • Throws on invalid PostgreSQL syntax instead of guessing

Unsupported SQL

Unsupported SQL is passed through with minimal normalization. For example, a SELECT statement is kept as-is apart from trailing semicolon cleanup.

This makes the plugin safe to use on mixed files only if you are comfortable with supported PostgreSQL DDL being reformatted while unsupported SQL mostly stays in its original layout.

Limitations

  • This is not a general-purpose SQL formatter
  • The scope is PostgreSQL-oriented DDL, not multi-dialect SQL
  • CREATE TABLE support is limited to tables the parser can map into the plugin's supported entry model
  • There are currently no plugin-specific options

Development

npm test