Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
08811a6
priv_name => upper
pyramation Jun 25, 2025
38ba001
casts
pyramation Jun 25, 2025
87e7282
Implement :: syntax for pg_catalog types in TypeCast method
pyramation Jun 25, 2025
763afde
Extend :: syntax to function calls for pg_catalog types
pyramation Jun 25, 2025
1d88675
updates for tests
pyramation Jun 26, 2025
b740605
Implement pretty printing formatting rules
pyramation Jun 26, 2025
4d5384e
Enhance SELECT formatting with expression complexity detection
pyramation Jun 26, 2025
d332396
fix snaps
pyramation Jun 26, 2025
678f1e1
pretty
pyramation Jun 26, 2025
9b9466a
pretty test
pyramation Jun 26, 2025
1f2f05c
Fix CREATE POLICY quote handling to only quote when necessary
pyramation Jun 26, 2025
0b1895b
add more test cases
pyramation Jun 26, 2025
d69372c
Fix case sensitivity in trigger function arguments
pyramation Jun 26, 2025
503aa4f
casing
pyramation Jun 26, 2025
3d14f8c
Add pretty printing for ALTER TABLE ADD CONSTRAINT
pyramation Jun 26, 2025
f459194
more test cases for pretty print
pyramation Jun 26, 2025
42fd87f
Enhance constraint pretty printing formatting
pyramation Jun 26, 2025
3880e3d
Fix constraint pretty printing formatting
pyramation Jun 26, 2025
0b0f2b4
Enhance constraint indentation tracking and formatting
pyramation Jun 26, 2025
7a9eca9
Fix CHECK constraint closing parenthesis alignment
pyramation Jun 26, 2025
e247c55
Revert "Fix CHECK constraint closing parenthesis alignment"
pyramation Jun 26, 2025
512cb83
pretty
pyramation Jun 26, 2025
49d3cc1
Implement strict INSERT INTO ... VALUES formatting for pretty printing
pyramation Jun 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 124 additions & 10 deletions __fixtures__/generated/generated.json

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions __fixtures__/kitchen-sink/pretty/casing.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
-- 1. Insert with simple mixed-case string
INSERT INTO users (name) VALUES ('John Doe');

-- 2. Insert with ALL CAPS
INSERT INTO users (name) VALUES ('ADMINISTRATOR');

-- 3. Insert with lowercase only
INSERT INTO users (name) VALUES ('lowercase');

-- 4. Insert with camelCase
INSERT INTO users (name) VALUES ('camelCaseString');

-- 5. Insert with snake_case
INSERT INTO users (name) VALUES ('snake_case_string');

-- 6. Insert with kebab-case (string literal)
INSERT INTO users (name) VALUES ('kebab-case-value');

-- 7. Insert with JSON-looking string
INSERT INTO data.snapshots (metadata) VALUES ('{"Type": "Full", "Status": "OK"}');

-- 8. Insert into quoted table and column
INSERT INTO "AppSchema"."User Data" ("Full Name") VALUES ('Jane Smith');

-- 9. Insert multiple values with mixed casing
INSERT INTO logtable (message) VALUES ('Init'), ('Reboot'), ('ERROR'), ('Warning'), ('info');

-- 10. Insert a string that looks like a function
INSERT INTO metrics.logs (message) VALUES ('NOW()');

-- 11. Insert with exact keyword-looking string
INSERT INTO users (name) VALUES ('SELECT');

-- 12. Insert lowercase string with special characters
INSERT INTO users (name) VALUES ('john_doe@example.com');

-- 13. Select mixed-case string literal
SELECT 'MixedCase';

-- 14. Select all uppercase
SELECT 'UPPERCASE';

-- 15. Select lowercase
SELECT 'lowercase';

-- 16. Select camelCase
SELECT 'camelCase';

-- 17. Select snake_case
SELECT 'snake_case';

-- 18. Select kebab-case
SELECT 'kebab-case';

-- 19. Select string that looks like SQL
SELECT 'SELECT * FROM users';

-- 20. Select string that looks like a function
SELECT 'sum(a + b)';

-- 21. Select with alias and quoted output name
SELECT name AS "UserLabel" FROM users;

-- 22. Select where literal is camelCase
SELECT * FROM users WHERE name = 'camelCaseString';

-- 23. Select where literal is lowercase
SELECT * FROM users WHERE name = 'lowercase';

-- 24. Select where literal is ALL CAPS
SELECT * FROM users WHERE name = 'ADMINISTRATOR';

-- 25. Select where message starts with capital W
SELECT * FROM logs WHERE message LIKE 'Warn%';

-- 26. Select with multiple casing in IN clause
SELECT * FROM alerts WHERE level IN ('Low', 'MEDIUM', 'High', 'CRITICAL');

-- 27. Select string with escaped quote
SELECT 'It''s working';

-- 28. Select with E-prefixed escape string
SELECT E'Line1\\nLine2';

-- 29. Select with Unicode emoji string
SELECT 'Status: ✅';

-- 30. Select into quoted alias
SELECT 'ALERT' AS "Level";

-- 31. Select with quoted function name
SELECT "HandleInsert"('TYPE_A', 'Region-1');

-- 32. Select with quoted table name
SELECT * FROM "dataPoints";
81 changes: 81 additions & 0 deletions __fixtures__/kitchen-sink/pretty/constraints.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
-- 1. Add a named primary key constraint
ALTER TABLE public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);

-- 2. Add a quoted unique constraint on a mixed-case column
ALTER TABLE "App"."User Data"
ADD CONSTRAINT "Unique_Full Name" UNIQUE ("Full Name");

-- 3. Add a composite unique constraint with custom name
ALTER TABLE school.attendance
ADD CONSTRAINT attendance_unique UNIQUE ("Student ID", "Class ID");

-- 4. Add a foreign key with quoted constraint and schema-qualified reference
ALTER TABLE "Orders"."OrderLines"
ADD CONSTRAINT "FK_Order_Ref" FOREIGN KEY (order_id)
REFERENCES "Orders"."Order"("OrderID");

-- 5. Add a check constraint with a regex pattern
ALTER TABLE "x-Schema"."z-Table"
ADD CONSTRAINT "zNameFormatCheck" CHECK ("Z-Name" ~ '^[A-Z]');

-- 6. Add a check constraint on JSON key existence
ALTER TABLE data.snapshots
ADD CONSTRAINT metadata_has_key CHECK (metadata ? 'type');

-- 7. Add a foreign key referencing quoted schema.table.column
ALTER TABLE "Billing"."Invoices"
ADD CONSTRAINT "FK_Client_ID"
FOREIGN KEY ("Client ID") REFERENCES "Clients"."ClientBase"("Client ID");

-- 8. Add a primary key on a quoted identifier
ALTER TABLE "API Keys"
ADD CONSTRAINT "PK_KeyID" PRIMARY KEY ("KeyID");

-- 9. Add a check on numeric range
ALTER TABLE finance.transactions
ADD CONSTRAINT tax_rate_range CHECK (tax_rate >= 0 AND tax_rate <= 1);

-- 10. Add a multi-column foreign key with custom name
ALTER TABLE school.enrollments
ADD CONSTRAINT fk_student_course FOREIGN KEY (student_id, course_id)
REFERENCES school.courses_students(student_id, course_id);

-- 11.
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
Expand All @@ -9,13 +53,50 @@ CREATE TABLE orders (
CONSTRAINT check_status CHECK (status IN ('pending', 'completed', 'cancelled'))
);

-- 12.

ALTER TABLE products ADD CONSTRAINT fk_category
FOREIGN KEY (category_id)
REFERENCES categories(id)
ON UPDATE CASCADE
ON DELETE SET NULL
DEFERRABLE INITIALLY DEFERRED;

-- 13

ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0);

-- 14

ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email);


-- 15

ALTER TABLE school.enrollments
ADD CONSTRAINT fk_student_course
FOREIGN KEY (student_id, course_id)
REFERENCES school.courses_students (student_id, course_id);

-- 16

ALTER TABLE school.enrollments
ADD CONSTRAINT chk_enrollment_date
CHECK (
enrollment_date <= CURRENT_DATE
AND status IN ('active', 'completed', 'withdrawn')
);

-- 17

CREATE TABLE school.enrollments (
student_id INT NOT NULL,
course_id INT NOT NULL,
enrollment_date DATE NOT NULL,
status TEXT CHECK (
status IN ('active', 'completed', 'withdrawn')
),
CHECK (
enrollment_date <= CURRENT_DATE
)
);
6 changes: 6 additions & 0 deletions __fixtures__/kitchen-sink/pretty/create_policy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ CREATE POLICY complex_policy ON documents
);

CREATE POLICY simple_policy ON posts FOR SELECT TO public USING (published = true);

CREATE POLICY "simple_policy" ON posts FOR SELECT TO public USING (published = true);

CREATE POLICY "Simple Policy" ON posts FOR SELECT TO public USING (published = true);

CREATE POLICY SimplePolicy ON posts FOR SELECT TO public USING (published = true);
9 changes: 9 additions & 0 deletions __fixtures__/kitchen-sink/pretty/create_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ CREATE TEMPORARY TABLE temp_calculations (
value DECIMAL(15,5),
result TEXT
);

CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
total DECIMAL(10,2) CHECK (total > 0),
status VARCHAR(20) DEFAULT 'pending',
created_at TIMESTAMP DEFAULT now(),
FOREIGN KEY (user_id) REFERENCES users(id)
);
7 changes: 7 additions & 0 deletions __fixtures__/kitchen-sink/pretty/cte.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
WITH regional_sales AS (SELECT region, SUM(sales_amount) as total_sales FROM sales GROUP BY region) SELECT * FROM regional_sales;

WITH regional_sales AS (SELECT region, SUM(sales_amount) as total_sales FROM sales GROUP BY region), top_regions AS (SELECT region FROM regional_sales WHERE total_sales > 1000000) SELECT * FROM top_regions;

WITH RECURSIVE employee_hierarchy AS (SELECT id, name, manager_id, 1 as level FROM employees WHERE manager_id IS NULL UNION ALL SELECT e.id, e.name, e.manager_id, eh.level + 1 FROM employees e JOIN employee_hierarchy eh ON e.manager_id = eh.id) SELECT * FROM employee_hierarchy;

WITH sales_summary AS (SELECT region, product_category, SUM(amount) as total FROM sales GROUP BY region, product_category), regional_totals AS (SELECT region, SUM(total) as region_total FROM sales_summary GROUP BY region) SELECT s.region, s.product_category, s.total, r.region_total FROM sales_summary s JOIN regional_totals r ON s.region = r.region;
17 changes: 17 additions & 0 deletions __fixtures__/kitchen-sink/pretty/misc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,20 @@ SELECT
ELSE 'normal'
END AS tier
FROM players;

-- 14. A trigger

CREATE TRIGGER decrease_job_queue_count_on_delete
AFTER DELETE ON dashboard_jobs.jobs
FOR EACH ROW
WHEN ( OLD.queue_name IS NOT NULL )
EXECUTE PROCEDURE dashboard_jobs.tg_decrease_job_queue_count ();

-- 15. default privileges

ALTER DEFAULT PRIVILEGES IN SCHEMA dashboard_jobs
GRANT EXECUTE ON FUNCTIONS TO administrator;

-- 16. grant execute on function

GRANT EXECUTE ON FUNCTION dashboard_private.uuid_generate_seeded_uuid TO PUBLIC;
29 changes: 29 additions & 0 deletions __fixtures__/kitchen-sink/pretty/procedures.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- 1. Simple function call with one string arg
SELECT handle_insert('TYPE_A');

-- 2. Function call with mixed-case literal (should preserve case)
SELECT "HandleInsert"('TYPE_A', 'Region-1');

-- 3. Function call with numeric and boolean args
SELECT compute_score(42, TRUE);

-- 4. Schema-qualified function call
SELECT metrics.get_total('2025-01-01', '2025-01-31');

-- 5. Function call in WHERE clause
SELECT * FROM users WHERE is_active(user_id);

-- 6. Function call returning composite type
SELECT * FROM get_user_details(1001);

-- 7. Function call inside FROM clause (set-returning)
SELECT * FROM get_recent_events('login') AS events;

-- 8. Function call with quoted identifiers and args
SELECT "Analytics"."RunQuery"('Q-123', '2025-06');

-- 9. Function call with nested expressions
SELECT calculate_discount(price * quantity, customer_tier);

-- 10. Procedure-style call (PL/pgSQL do-nothing)
SELECT perform_backup('daily', FALSE);
29 changes: 0 additions & 29 deletions __fixtures__/kitchen-sink/pretty/select_statements.sql

This file was deleted.

Loading