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
3 changes: 3 additions & 0 deletions crates/squawk_fmt/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6518,6 +6518,9 @@ fn build_set_role<'a>(ctx: &Ctx, set: &ast::SetRole) -> Doc<'a> {
.nest(ctx.indent),
);
}
if let Some(to) = set.to_token() {
doc = doc.append(line_before(&to).append(Doc::text("to")).nest(ctx.indent));
}
if let Some(target) = set.set_role_target() {
doc = doc.append(
line_before(target.syntax())
Expand Down
2 changes: 2 additions & 0 deletions crates/squawk_fmt/tests/after/set_role.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set role group legacy_user;

set role 'literal role';

set role to 'api';

set
session
role
Expand Down
2 changes: 2 additions & 0 deletions crates/squawk_fmt/tests/before/set_role.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set role group legacy_user;

set role 'literal role';

set role to 'api';

set session role an_intentionally_long_role_name_that_makes_this_statement_longer_than_eighty_characters;

/* before set */ SET /* before scope */ LOCAL /* before role */ ROLE /* before target */ GROUP /* before role name */ legacy_user /* before semicolon */;
5 changes: 3 additions & 2 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15462,15 +15462,16 @@ fn opt_set_scope(p: &mut Parser<'_>) {
m.complete(p, kind);
}

// SET [ SESSION | LOCAL ] ROLE role_name
// SET [ SESSION | LOCAL ] ROLE NONE
// SET [ SESSION | LOCAL ] ROLE [ TO ] role_name
// SET [ SESSION | LOCAL ] ROLE [ TO ] NONE
// RESET ROLE
fn set_role(p: &mut Parser<'_>) -> CompletedMarker {
assert!(p.at(SET_KW));
let m = p.start();
p.bump(SET_KW);
opt_set_scope(p);
p.expect(ROLE_KW);
p.eat(TO_KW);
if p.at(NONE_KW) {
let target = p.start();
p.bump(NONE_KW);
Expand Down
2 changes: 2 additions & 0 deletions crates/squawk_parser/tests/data/ok/set_role.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ SET SESSION ROLE foo;

set role 'fooo';

set role to 'api';

RESET ROLE;

11 changes: 11 additions & 0 deletions crates/squawk_parser/tests/snapshots/tests__set_role_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ SOURCE_FILE
STRING "'fooo'"
SEMICOLON ";"
WHITESPACE "\n\n"
SET_ROLE
SET_KW "set"
WHITESPACE " "
ROLE_KW "role"
WHITESPACE " "
TO_KW "to"
WHITESPACE " "
LITERAL
STRING "'api'"
SEMICOLON ";"
WHITESPACE "\n\n"
RESET_ROLE
RESET_KW "RESET"
WHITESPACE " "
Expand Down
4 changes: 4 additions & 0 deletions crates/squawk_syntax/src/ast/generated/nodes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/squawk_syntax/src/postgresql.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -5818,7 +5818,7 @@ Immediate =
'immediate'

SetRole =
'set' SetScope? 'role' SetRoleTarget ';'?
'set' SetScope? 'role' 'to'? SetRoleTarget ';'?

SetRoleTarget =
RoleRef
Expand Down
Loading