Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10,821 changes: 10,072 additions & 749 deletions crates/squawk_fmt/src/fmt.rs

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions crates/squawk_fmt/tests/after/alter_publication.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/alter_publication.sql
---
alter publication selected_tables
add table public.new_accounts, tables in schema archive;

alter publication selected_tables drop table public.old_accounts;

alter publication selected_tables
set table public.accounts (id) where (id > 200);

alter publication everything
set all tables, all sequences except (table private.tokens, audit.logs);

alter publication everything set (publish = 'insert, update');

alter publication everything owner to replication_admin;

alter publication everything rename to all_changes;

alter /* after alter */ publication /* before name */ commented_pub
set
/* before object */ table /* before table name */ public.commented,
/* after comma */ current_schema/* before semicolon */;
35 changes: 35 additions & 0 deletions crates/squawk_fmt/tests/after/alter_subscription.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/alter_subscription.sql
---
alter subscription local_sub connection 'host=otherhost dbname=publisher';

alter subscription local_sub server publisher_server;

alter subscription local_sub
set (slot_name = new_slot, synchronous_commit = local);

alter subscription local_sub
add publication another_publication, third_publication with (copy_data = false);

alter subscription local_sub set publication all_changes with (refresh = true);

alter subscription local_sub
drop publication selected_tables with (refresh = false);

alter subscription local_sub refresh publication with (copy_data = true);

alter subscription local_sub enable;

alter subscription local_sub disable;

alter subscription local_sub skip (lsn = '0/16B6C50');

alter subscription local_sub owner to replication_admin;

alter subscription local_sub rename to renamed_sub;

alter /* after alter */ subscription /* after subscription */ renamed_sub
add /* after add */ publication /* before publication name */ commented_pub,
/* after publication comma */ selected_tables
with /* before params */ (copy_data = true)/* before semicolon */;
30 changes: 30 additions & 0 deletions crates/squawk_fmt/tests/after/analyze.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/analyze.sql
---
analyze;

analyse verbose records;

analyze public.records (id, payload), public.archived_records;

analyze (
verbose true, skip_locked false, buffer_usage_limit '4MB'
)
public.records;

analyze
an_intentionally_long_schema_name.an_intentionally_long_table_name_that_makes_this_statement_exceed_eighty_characters (
an_intentionally_long_column_name
);

/* before analyze */
analyze /* before options */ (
/* before verbose */ verbose /* before true */ true /* before comma */,
/* before skip locked */ skip_locked /* before false */ false /* before close */
)
/* before table */ public /* before dot */./* after dot */ records /* before columns */ (
/* before id */ id /* before column comma */,
/* before payload */ payload /* before columns close */
) /* before table comma */,
/* before second table */ archived_records/* before semicolon */;
22 changes: 22 additions & 0 deletions crates/squawk_fmt/tests/after/call.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/call.sql
---
call refresh_materialized_data();

call public.process_record(1, 'record', enabled => true);

call process_a_record_with_an_intentionally_long_procedure_name(
an_intentionally_long_argument_name => 'an intentionally long argument value',
another_intentionally_long_argument_name => 12345
);

/* before */
call /* after call */ public /* before dot */./* after dot */ process_record /* before left paren */(
/* after left paren */ 1 /* before comma */,
/* after comma */ argument_name /* before arrow */ => /* after arrow */ 'value' /* before second comma */,
/* after second comma */ variadic /* after variadic */ array[
1,
2
] /* before right paren */
)/* before semicolon */;
24 changes: 24 additions & 0 deletions crates/squawk_fmt/tests/after/checkpoint.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/checkpoint.sql
---
checkpoint;

checkpoint (mode fast);

checkpoint (mode spread, flush_unlogged true);

checkpoint (flush_unlogged false);

checkpoint (flush_unlogged);

checkpoint (
an_intentionally_long_checkpoint_option_name an_intentionally_long_value_name,
another_intentionally_long_checkpoint_option_name another_intentionally_long_value_name
);

/* before checkpoint */
checkpoint /* before left paren */ (
/* after left paren */ mode /* before value */ fast /* before comma */,
/* after comma */ flush_unlogged /* before second value */ false /* before right paren */
)/* before semicolon */;
17 changes: 17 additions & 0 deletions crates/squawk_fmt/tests/after/close.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/close.sql
---
close all;

close active_cursor;

close "Case-Sensitive Cursor";

close
cursor_with_an_intentionally_long_name_that_makes_this_close_statement_longer_than_eighty_characters;

/* before */
close /* after close */ all/* before semicolon */;

close /* before cursor */ cursor_name/* before cursor semicolon */;
31 changes: 31 additions & 0 deletions crates/squawk_fmt/tests/after/cluster.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/cluster.sql
---
cluster;

cluster verbose;

cluster records;

cluster verbose public.records using records_created_at_idx;

cluster records_created_at_idx on public.records;

cluster
(verbose true, analyze false)
a_very_long_schema_name.an_intentionally_long_table_name
using a_very_long_schema_name.an_intentionally_long_index_name;

/* before */
cluster
/* after cluster */ (
/* after left paren */ verbose /* before comma */,
/* after comma */ analyze /* before value */ true /* before right paren */
)
/* before table */ public /* before table dot */./* after table dot */ records
/* before using */ using /* after using */ public /* before index dot */./* after index dot */ records_idx/* before semicolon */;

cluster
/* before legacy index */ public /* before legacy index dot */./* after legacy index dot */ records_idx
/* before on */ on /* after on */ public /* before legacy table dot */./* after legacy table dot */ records/* before legacy semicolon */;
53 changes: 53 additions & 0 deletions crates/squawk_fmt/tests/after/compound_select.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/compound_select.sql
---
select 1 union select 2;

select 1 union all select 2 intersect distinct select 3 except select 4;

(select 1)
except
(select 2)
order by 1;

(select 1);

select 1
union
select 2
order by 1
for update
limit 10
offset 2 rows;

select 1
union
select 2
fetch first 5 rows with ties;

select 1
union
select 2
for no key update of foo, bar skip locked;

table foo union values (1), (2);

select
/* after select */ a_very_long_first_column_name,
a_very_long_second_column_name
from a_very_long_first_table_name
/* before union */ union /* before all */ all
/* before rhs */ select
/* rhs select */ a_very_long_first_column_name,
a_very_long_second_column_name
from a_very_long_second_table_name/* before semicolon */;

select 1
/* before operator */ union /* before quantifier */ distinct
/* before right select */ select 2;
select 1
-- before operator
union all
-- before right select
select 2;
55 changes: 55 additions & 0 deletions crates/squawk_fmt/tests/after/copy.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/copy.sql
---
copy foo from '/tmp/foo.csv';

copy foo (id, name)
to stdout
with (format csv, header true, delimiter ',', null '', encoding 'UTF8');

copy (
select id, a_very_long_column_name, another_very_long_column_name
from a_very_long_schema_name.a_very_long_table_name
)
to program 'gzip > /tmp/a_very_long_output_file_name.csv'
with (format csv, header on);

copy binary foo
from stdin
binary
freeze
csv
header
json
delimiter as ','
null as ''
quote as '"'
escape as '\\'
encoding 'UTF8'
force not null id, name
force quote *
force null description
where id > 0;

/* before */
copy /* after copy */ binary /* after binary */ public /* before dot */./* after dot */ records /* before columns */ (
/* after left paren */ id /* before comma */,
/* after comma */ description /* before right paren */
)
/* before from */ from /* after from */ program /* after program */ 'cat /tmp/records'
/* before with */ with /* before options */ (
/* after options left paren */ format /* before format value */ csv /* before option comma */,
/* after option comma */ header /* before header value */ on /* before second option comma */,
/* after second option comma */ force_null /* before nested options */ (
/* after nested left paren */ id /* before nested comma */,
/* after nested comma */ description /* before nested right paren */
) /* before options right paren */
)
/* before where */ where /* after where */ id > 0/* before semicolon */;

copy (
/* after query left paren */ select /* after select */ id
from records /* before query right paren */
)
to /* before stdout */ stdout;
53 changes: 53 additions & 0 deletions crates/squawk_fmt/tests/after/create_foreign_table.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: crates/squawk_fmt/tests/tests.rs
input_file: crates/squawk_fmt/tests/before/create_foreign_table.sql
---
create foreign table t () server s;

create foreign table if not exists public.remote_records (
id bigint not null,
name text,
constraint remote_records_pkey primary key (id)
)
inherits (public.base_records)
server foreign_server
options (
schema_name 'public',
table_name 'records'
);

create foreign table partition_records
partition of public.records (
id with options not null,
name
) default
server foreign_server;

create foreign table ranged_records
partition of public.records (id)
for values from (1) to (100)
server foreign_server
options (
table_name 'ranged_records'
);

create foreign table an_intentionally_long_schema_name.an_intentionally_long_foreign_table_name (
an_intentionally_long_column_name character varying,
another_intentionally_long_column_name timestamp with time zone
)
server an_intentionally_long_foreign_server_name
options (
schema_name 'an_intentionally_long_schema_name',
table_name 'an_intentionally_long_foreign_table_name'
);

/* before create */
create /* before foreign */ foreign /* before table */ table /* before if */ if /* before not */ not /* before exists */ exists /* before table name */ public /* before dot */./* after dot */ remote_records/* before left paren */ (
/* after left paren */ id /* before type */ bigint /* before comma */,
/* after comma */ name /* before second type */ text /* before right paren */
)
/* before server */ server /* before server name */ foreign_server
/* before options */ options /* before options left paren */(
/* after options left paren */ schema_name /* before option value */ 'public' /* before option comma */,
/* after option comma */ table_name /* before second option value */ 'records' /* before options right paren */
)/* before semicolon */;
Loading
Loading