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 🙏

© 2024 – Pkg Stats / Ryan Hefner

prettier-plugin-pg

v0.0.0

Published

A prettier plugin for formatting PostgreSQL-flavour SQL

Downloads

4

Readme

prettier-plugin-pg

Package on npm MIT license Gitter chat room Donate Follow

This is a work-in-progress plugin for prettier to support formatting of PostgreSQL-flavour SQL, including formatting view and function bodies as SQL, PL/pgSQL, Python (plpython), JavaScript (plv8) etc.

Guiding principles

Try and match pg_dump-style capitalisation and word order, but with prettier line-wrapping/indentation.

  • Capitalise keywords
  • Use lower case for case-insensitive identifiers (table/column/function/etc names)
  • Only escape case-insensitive identifiers if they are reserved words
  • Always escape identifiers if they are reserved words
  • Always escape case-sensitive identifiers (obviously)
  • Where a statement can be expressed in many orders, express it in the same order that pg_dump would
  • Try not to add/remove things (e.g. functions are volatile by default, mark them as VOLATILE in the output if and only if they were marked as such in the input (otherwise omit))
  • Be safe! If we don't understand something, throw an error - don't just carry on regardless!

How to use it

Don't! We're not ready yet!

git clone [email protected]:benjie/prettier-plugin-pg.git
cd prettier-plugin-pg
yarn
npm run test

How it works / history

We use pg-query-native which uses libpq_query to parse the SQL using the same parser code that PostgreSQL uses internally.

We then took the deparser from pg-query-parser as the foundation for the printer, and converted it from using strings internally to using prettier's formatting commands. [This is where we're working currently.]

We've not got this far yet, but next we'll be adding a library of tests (if you have any particularly tricky SQL, please submit it!) to ensure that nothing is corrupted.

Finally we'll be optimising the formatting of the output queries - putting the groups and lines in the correct places.

Status

Very much a work in progress - do NOT use this for basically ANYTHING yet, we've got a long way to go.

Contributing

Help would be very much appreciated - just jot down in an issue what you'd like to do and if you get the nod (which tends to be fairly prompt!) then please send a PR. Issues will be opened up to other contributors after a short period of inactivity, so you're encouraged to open a PR before it's ready to merge, just mark it as [WIP] in the PR title.

Self-promotion

While I've got your attention:

  • my open source work is self-funded through freelance consulting work and generous donations from the community, you can support my open source work via Patreon, or PayPal
  • you can follow me on Twitter: @benjie
  • if you're looking for an instant GraphQL server for your PostgreSQL database that leverages the power of PostgreSQL and doesn't fall foul of N+1 issues, check out PostGraphile (formerly PostGraphQL)