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 changes: 9 additions & 1 deletion crates/squawk_fmt/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ fn build_insert<'a>(ctx: &Ctx, insert: &ast::Insert) -> Doc<'a> {
.append(space_before(alias.syntax()))
.append(build_required_as_alias(alias));
}
let has_columns = insert.column_target_list().is_some();
if let Some(columns) = insert.column_target_list() {
doc = doc
.append(space_before(columns.syntax()))
Expand All @@ -323,7 +324,14 @@ fn build_insert<'a>(ctx: &Ctx, insert: &ast::Insert) -> Doc<'a> {
.append(build_overriding_clause(overriding));
}
if let Some(source) = insert.insert_source() {
let before_source = line_before(source.syntax());
let before_source = match &source {
ast::InsertSource::SelectVariant(ast::SelectVariant::Values(_))
if has_columns && insert.overriding_clause().is_none() =>
{
space_before(source.syntax())
}
_ => line_before(source.syntax()),
};
match source {
ast::InsertSource::SelectVariant(ast::SelectVariant::Values(values))
if values
Expand Down
11 changes: 7 additions & 4 deletions crates/squawk_fmt/tests/after/create_function.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ create function record_and_calculate(
) returns integer
language sql
begin atomic
insert into function_audit_log (first_recorded_value, second_recorded_value)
values (
insert into function_audit_log (
first_recorded_value,
second_recorded_value
) values (
a_very_long_input_parameter_name, another_very_long_input_parameter_name
);
return a_very_long_input_parameter_name
Expand All @@ -145,8 +147,9 @@ create function record_and_calculate(
create function commented_body(value integer) returns integer
language sql
/*bb*/ begin /*bc*/ atomic
/*bd*/ insert /*be*/ into function_log /*bf*/ (value)
/*bg*/ values /*bh*/ (value) /*bi*/;
/*bd*/ insert /*be*/ into function_log /*bf*/ (value) /*bg*/ values /*bh*/ (
value
) /*bi*/;
/*bj*/ return /*bk*/ value + 1 /*bl*/;
/*bm*/ end /*bn*/;

Expand Down
6 changes: 6 additions & 0 deletions crates/squawk_fmt/tests/after/create_index.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ create index reservations_during_idx
create index documents_search_idx
on documents using gin (search_vector);

create unique index
on /* TEMPLATE: schema */ river_migration using btree (version);

create index river_job_metadata_index
on /* TEMPLATE: schema */ river_job using gin (metadata);

create index long_index_name_for_testing_line_wrapping
on long_schema_name.a_very_long_table_name
using btree (
Expand Down
34 changes: 30 additions & 4 deletions crates/squawk_fmt/tests/after/insert.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ with inserted as (
insert into a_very_long_schema_name.a_very_long_table_name (
organization_identifier,
extremely_long_descriptive_column_name
)
values (
) values (
123456789,
'an extremely long value that forces the insert statement to wrap across lines'
)
Expand Down Expand Up @@ -105,11 +104,38 @@ on conflict (unique_key)
do update
set kind = excluded.kind;

insert into t (a)
values (1)
insert into t (a) values (1)
on conflict (a)
do select
for update of this_is_a_very_long_table_name_that_forces_the_conflict_action_to_wrap
where
this_is_a_very_long_column_name_that_forces_the_where_clause_to_wrap > 0
returning *;

insert into river_job (
args,
created_at,
kind,
max_attempts,
metadata,
priority,
queue,
scheduled_at,
state,
tags,
unique_key,
unique_states
) values (
@args,
@created_at,
@kind,
@max_attempts,
@metadata,
@priority,
@queue,
@scheduled_at,
@state,
@tags,
@unique_key,
@unique_states
);
4 changes: 4 additions & 0 deletions crates/squawk_fmt/tests/before/create_index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ create index reservations_during_idx on reservations using gist (during);

create index documents_search_idx on documents using gin (search_vector);

create unique index on /* TEMPLATE: schema */ river_migration using btree (version);

create index river_job_metadata_index on /* TEMPLATE: schema */ river_job using gin (metadata);

create index long_index_name_for_testing_line_wrapping on long_schema_name.a_very_long_table_name using btree (a_very_long_column_name, another_very_long_column_name, a_third_very_long_column_name) include (a_very_long_included_column_name) nulls distinct where a_very_long_column_name is not null;

-- comments in every position
Expand Down
29 changes: 29 additions & 0 deletions crates/squawk_fmt/tests/before/insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,32 @@ ON CONFLICT (unique_key)
DO UPDATE SET kind = EXCLUDED.kind;

insert into t(a) values(1) on conflict(a) do select for update of this_is_a_very_long_table_name_that_forces_the_conflict_action_to_wrap where this_is_a_very_long_column_name_that_forces_the_where_clause_to_wrap > 0 returning *;

insert into river_job (
args,
created_at,
kind,
max_attempts,
metadata,
priority,
queue,
scheduled_at,
state,
tags,
unique_key,
unique_states
)
values (
@args,
@created_at,
@kind,
@max_attempts,
@metadata,
@priority,
@queue,
@scheduled_at,
@state,
@tags,
@unique_key,
@unique_states
);
Loading