-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correction indentation when the HAVING clause contains AND/OR (#50)
- Loading branch information
Showing
8 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ mod for_update; | |
mod frame; | ||
mod from; | ||
mod group_by; | ||
mod having; | ||
mod join; | ||
mod limit; | ||
mod offset; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use tree_sitter::TreeCursor; | ||
|
||
use crate::{ | ||
cst::*, | ||
error::UroboroSQLFmtError, | ||
visitor::{create_clause, ensure_kind, Visitor}, | ||
}; | ||
|
||
impl Visitor { | ||
/// HAVING句をClauseで返す | ||
pub(crate) fn visit_having_clause( | ||
&mut self, | ||
cursor: &mut TreeCursor, | ||
src: &str, | ||
) -> Result<Clause, UroboroSQLFmtError> { | ||
cursor.goto_first_child(); | ||
|
||
let mut clause = create_clause(cursor, src, "HAVING")?; | ||
cursor.goto_next_sibling(); | ||
self.consume_comment_in_clause(cursor, src, &mut clause)?; | ||
|
||
// cursor -> _expression | ||
let expr = self.visit_expr(cursor, src)?; | ||
|
||
// 結果として得られた式をBodyに変換する | ||
let body = Body::from(expr); | ||
|
||
clause.set_body(body); | ||
|
||
// cursorを戻す | ||
cursor.goto_parent(); | ||
ensure_kind(cursor, "having_clause", src)?; | ||
|
||
Ok(clause) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
select | ||
id as id | ||
, sum(cnt) | ||
from | ||
tbl | ||
group by | ||
id | ||
having | ||
/* comment */ | ||
sum(cnt) > 1 | ||
and avg(cnt) < 10 | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
select | ||
id, sum(cnt) | ||
from | ||
tbl | ||
group by | ||
id | ||
having | ||
/* comment */ | ||
sum(cnt) > 1 and avg(cnt) < 10 | ||
; |