Little idea, I've seen templating languages that e...
# komapper
d
Little idea, I've seen templating languages that either ignore whitespace or not depending on how the directives are declared (like
/*-
for removing whitespace before the directive), this could be useful when declaring more complex
@KomapperCommands
, keeping normal formatting for the sql while still staying within the editor's bounderies (not having to scroll horizontally too much...), what do you think @Toshihiro Nakamura?
For example I have a WHERE statement, and an if directive whether to add an AND to it. If I put it on a separate line, I'd get an empty line when the AND doesn't get added to the sql. This not-so-nice formatting problem affects errors returned, and some unit tests testing complex sql statements.
t
Komapper automatically removes empty lines. For example, consider the following SQL template:
Copy code
select * from address where 
version = /*version*/0
/*%if street != null*/
and
street = /*street*/''
/*%end*/
order by address_id
If the
street
parameter is null, it will be converted to the following SQL:
Copy code
select * from address where
version = ?
order by address_id
So, in most cases, unnecessary spaces shouldn’t be an issue. However, what kind of SQL template are you using in your use case?
d
That's good to know that empty lines are removed! I'm starting to use commands more now for migration of our current sqls, I'll let you know if I encounter any weird cases that might need better white space control, thanks!
👍 1