Skip to content

Commit

Permalink
Support bind parameter in first colomn of select clause (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppputtyo authored Nov 8, 2023
1 parent 3128fb8 commit f903fd5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/uroborosql-fmt/src/cst/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Body {
Body::Insert(_) => false,
Body::With(_) => false,
Body::SingleLine(single_line) => single_line.try_set_head_comment(comment),
Body::Select(_) => false,
Body::Select(select) => select.try_set_head_comment(comment),
}
}
}
14 changes: 14 additions & 0 deletions crates/uroborosql-fmt/src/cst/body/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ impl SelectBody {
Ok(())
}

pub(crate) fn try_set_head_comment(&mut self, comment: Comment) -> bool {
// select_clause_bodyが存在し、空ではなく、先頭とコメントが隣接している場合
// select_clause_bodyの先頭要素にバインドパラメータをセットする
if let Some(select_clause_body) = &mut self.select_clause_body {
if let Some(select_clause_body_loc) = select_clause_body.loc() {
if comment.loc().is_next_to(&select_clause_body_loc) {
return select_clause_body.try_set_head_comment(comment);
}
}
}

false
}

pub(crate) fn is_empty(&self) -> bool {
self.all_distinct.is_none() && self.select_clause_body.is_none()
}
Expand Down
4 changes: 4 additions & 0 deletions crates/uroborosql-fmt/testfiles/dst/select/bind_param.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ from
where
t.a = /*var*/1
and /*var2*/1 = t.c
;
select /* _SQL_ID_ */
/*x*/'x' as x
, /*y*/'y' as y
6 changes: 5 additions & 1 deletion crates/uroborosql-fmt/testfiles/src/select/bind_param.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
select a, /*param*/'1' as b
from t
where t.a = /*var*/1
and /*var2*/1 = t.c
and /*var2*/1 = t.c;

select /* _SQL_ID_ */
/*x*/'x' as x
, /*y*/'y' as y

0 comments on commit f903fd5

Please sign in to comment.