Skip to main content

The SemiColon Style — a PostgreSQL SQL formatter

Project description

SemiColon

Philosophy

Most SQL formatters produce code that is syntactically correct but visually noisy.
The SemiColon Style treats SQL as prose: it has a rhythm, a visible structure, and a clear centre of gravity — the River.

The goal is not merely consistency; it is readability at a glance.

Installation

From PyPI

pip install semicolonfmt

From source

git clone https://github.com/mustafaa7med/semicolon.git
cd semicolon
pip install -e .

Verify

semicolon --version

Usage

Format a single file

semicolon query.sql

The file is formatted in-place.

Format all .sql files in the current directory

semicolon .

CI/CD check mode

semicolon query.sql --check   # exits 1 if formatting is needed
semicolon . --check           # check all .sql files

No files are written in --check mode — it is safe to use in pipelines.


Before & After

Before (messy, unformatted)

with
active_users as (
select u.id, u.name as user_name, u.email as user_email, u.created_at from users u where u.active = true and u.deleted_at is null
),
recent_orders as (
select o.user_id, count(*) as order_count, sum(o.total) as total_spent from orders o where o.created_at between '2024-01-01' and '2024-12-31' group by o.user_id
)
select au.user_name, au.user_email, ro.order_count, ro.total_spent from active_users au left join recent_orders ro on au.id = ro.user_id where ro.total_spent > 500 order by ro.total_spent desc limit 100;

After

WITH active_users AS(
    SELECT  u.id,
            u.name  AS user_name,
            u.email AS user_email,
            u.created_at
      FROM  users u
     WHERE  u.active = TRUE
       AND  u.deleted_at IS NULL
),

recent_orders AS(
    SELECT  o.user_id,
            COUNT(*)     AS order_count,
            SUM(o.total) AS total_spent
      FROM  orders o
     WHERE  o.created_at BETWEEN '2024-01-01'
                             AND '2024-12-31'
  GROUP BY  o.user_id
)

    SELECT  au.user_name,
            au.user_email,
            ro.order_count,
            ro.total_spent
      FROM  active_users au
 LEFT JOIN  recent_orders ro
        ON  au.id = ro.user_id
     WHERE  ro.total_spent > 500
  ORDER BY  ro.total_spent DESC
     LIMIT  100;

Pre-commit Integration

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/mustafaa7med/semicolon
    rev: v0.1.0
    hooks:
      - id: semicolon
        args: [--check]

License

Apache — see LICENSE.

Designed by Mostafa Ahmed (Alfie)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semicolonfmt-0.1.2.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semicolonfmt-0.1.2-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file semicolonfmt-0.1.2.tar.gz.

File metadata

  • Download URL: semicolonfmt-0.1.2.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for semicolonfmt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 65c6f4b6f91725b7f6c0ffd9308719b9cb0b6e6a11b1618f193976c24be17f11
MD5 6f3eee3da4b8d37d179f34963247669c
BLAKE2b-256 e96de5e14f5f57209e1fc9383097a2155c1cc0dd3cdbdeb7d034a37548b59c1e

See more details on using hashes here.

File details

Details for the file semicolonfmt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: semicolonfmt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for semicolonfmt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2407b859cfde2c973461974df297a342663ad008fdbf9e628e2ed5ee031fb297
MD5 18b9fe75e3d6e96a1a5c0fcdfc2d4d67
BLAKE2b-256 d18fb8f85f3045f0b324d9ed5f9bf9ebc201d9d99c76146d70c3e162a4d9064c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page