• Stars
    star
    279
  • Rank 147,967 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[WIP] Plugin for prettier to support formatting of PostgreSQL-flavour SQL, including function bodies in SQL, pgSQL, PLV8, plpython, etc.

prettier-plugin-pg

Package on npm MIT license Gitter chat room Patreon donate button 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

Then compile the source (watch flag is optional):

yarn tsc --watch

And in another terminal:

yarn 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)

More Repositories

1

mehserve

A simple port-sharing proxy for development on multiple local domains, supports websockets
JavaScript
79
star
2

flow2typescript

Flow to TypeScript converter
TypeScript
21
star
3

ouch-my-finger

JavaScript
16
star
4

hsbc-scrape

Command-line driven scraper to pull down your banking history from HSBC (UK)'s internet banking portal.
CoffeeScript
12
star
5

backbone-redis-store

NodeJS Backbone mode to enable Redis as data persistence layer
CoffeeScript
11
star
6

backbone-react

JavaScript
10
star
7

eslint-plugin-pg-sql

PostgreSQL plugin for ESLint that enables linting PLV8 JavaScript functions within SQL files
JavaScript
9
star
8

ec2-prune-snapshots

Prune snapshots of EBS volumes
PHP
9
star
9

graphql-bench-prisma

PostGraphile's changes to Prisma's benchmark built on top of Hasura's graphql-bench
JavaScript
9
star
10

rf-experiments

Capturing RF data using a cheap receiver and Arduino; attempting to decode it.
CoffeeScript
7
star
11

postgraphile-apple-example

An example of PostGraphile using data extracted from the Wikipedia page listing Apple's product releases
PLpgSQL
6
star
12

dotfiles

Benjie's dotfiles (not intended for public consumption)
Vim Script
6
star
13

weechat-colloquy

Colloquy iOS PUSH (APNS) support for Weechat relay/bouncer
Python
5
star
14

backbone-react-redux

JavaScript
5
star
15

react-technical-intro

A technical introduction to React
HTML
4
star
16

postgraphile-heroku-bench

Benchmark PostGraphile on Heroku free tier
4
star
17

kjsonl

An easy to parse file format for large amounts of key-value storage in JSON format
TypeScript
4
star
18

localrepo-pledge

Use @localrepo/* for your monorepo package names
JavaScript
4
star
19

benjie.dev

Book me 😉
HTML
3
star
20

dynargs

Specify and process JavaScript dynamic argument lists simply.
JavaScript
2
star
21

gibbot

A robot to serve the gibbons
CoffeeScript
2
star
22

MythPyWii

A Wiimote interface to MythTV written in Python
Python
2
star
23

backbone-null-store

Null storage engine for Backbone.js
CoffeeScript
2
star
24

Proximirun

Bluetooth proximity based AppleScript runner
Objective-C
2
star
25

potzy

Go crazy with potentiometers!
CoffeeScript
2
star
26

graphile-starter--private

A quick-start project with full account system (including registration, login, email verification and multiple email management, social login) powered by PostGraphile, TypeScript, Apollo, graphile-worker, graphile-migrate, Ant Design and Next.js
TypeScript
2
star
27

grafast-stripe-example

Grafast inlining example over Stripe: subscriptions is inlined into the customer fetch, but only when requested.
TypeScript
2
star
28

.dev

GraphQL advice from Benjie
MDX
2
star
29

pgselect-join-example

An example of using a join in a pgSelect step to order by related fields on another table. Also an example of using pgSelect/Grafast without PostGraphile.
JavaScript
2
star
30

zoomsync

A tool I wrote to sync Zoom recordings to YouTube for the various GraphQL Working Groups. Includes categorization logic, and automatic rejection of invalid (too short, too small) recordings.
TypeScript
1
star
31

openscad-dice-box

Dice box for my friend, hastily hacked together in OpenSCAD
OpenSCAD
1
star
32

postgraphile-lightning

WIP
PLpgSQL
1
star
33

sscad

A simple script to make editing OpenSCAD files more pleasant.
CoffeeScript
1
star
34

db-migrate-plugin-babel

Add babel support to db-migrate
JavaScript
1
star
35

javascript-flamegraph

FlameGraphs for JavaScript (mobile/browser/node.js/etc) to aid performance debugging.
CoffeeScript
1
star
36

rendr-error-handler

How do we add custom handling for errors in rendr?
JavaScript
1
star
37

cordova-vendor-apps

Allows you to check for existence, open or direct to app store for arbitrary apps.
Objective-C
1
star
38

dalekgl

A WebGL estimation of Dalek vision using your webcam.
CoffeeScript
1
star
39

twitter-following-cleaner

A tool for seeing which following twitter account's are active or not based on their latest tweet.
JavaScript
1
star
40

repo

Nothing to see here - this is just a repo I use for testing BOTS integrations. Content irrelevant
1
star
41

extend_demo

JavaScript
1
star
42

pggql

GraphQL schema utilities from PostgreSQL reflection
JavaScript
1
star
43

pasa-dalek

Dalek modifications to PASA (https://gitlab.com/nitroxis/pasa/)
C
1
star
44

javascript-problems

Programming problems in JavaScript to aid understanding.
1
star
45

node-simple-aws

A simple wrapper around AWS's official aws-sdk Node.JS module
JavaScript
1
star
46

nodejs-workshop

This is the slides from a workshop I'm running on Node.js (don't worry, there's lots more to the talk than is in these slides!)
JavaScript
1
star