Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,31 @@ mod tests {
assert_eq!(format(input, &QueryParams::None, &options), expected);
}

#[test]
fn it_recognizes_on_delete_set_null_clause() {
let input = indoc!(
"CREATE TABLE t (
c1 INT REFERENCES r (id) ON DELETE SET NULL,
c2 TEXT
);"
);
let options = FormatOptions {
uppercase: Some(true),
lines_between_queries: 2,
max_inline_top_level: Some(80),
..Default::default()
};
let expected = indoc!(
"
CREATE TABLE t (
c1 INT REFERENCES r (id) ON DELETE SET NULL,
c2 TEXT
);"
);

assert_eq!(format(input, &QueryParams::None, &options), expected);
}

#[test]
fn it_formats_except_on_columns() {
let input = indoc!(
Expand Down
2 changes: 2 additions & 0 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ fn get_top_level_reserved_token<'a>(
terminated("SELECT", end_of_word),
terminated("SET CURRENT SCHEMA", end_of_word),
terminated("SET SCHEMA", end_of_word),
terminated("SET NULL", end_of_word),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: SET DEFAULT is still tokenized as a top-level SET clause

This special-cases SET NULL, but referential actions also allow SET DEFAULT. For ON DELETE SET DEFAULT and ON UPDATE SET DEFAULT, the tokenizer will still match the plain SET branch here, classify it as ReservedTopLevel, and split the foreign-key action across lines again.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

terminated("SET", end_of_word),
))
.parse_next(&mut uc_input),
Expand Down Expand Up @@ -648,6 +649,7 @@ fn get_top_level_reserved_token<'a>(
{
TokenKind::Reserved
}
("SET NULL", _) => TokenKind::Reserved,
("SET", Some("UPDATE")) => TokenKind::ReservedNewlineAfter,
("USING", v) if v != Some("MERGE INTO") && v != Some("DELETE FROM") => {
TokenKind::Reserved
Expand Down