-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve dev workflow and add SQL code formatter #72
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #72 +/- ##
==========================================
- Coverage 83.10% 83.02% -0.09%
==========================================
Files 11 11
Lines 876 854 -22
Branches 165 161 -4
==========================================
- Hits 728 709 -19
+ Misses 67 66 -1
+ Partials 81 79 -2 |
.vscode/extensions.json
Outdated
{ | ||
"recommendations": [ | ||
"twxs.cmake", | ||
"bradymholt.pgformatter" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not commit commit custom editor configs in here. We will all have custom configs and we can each maintain those.
for pgformatter, we should have a make
target also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for pgformatter, we should have a make target also.
I added a make target! It's called format-sql
. Should I mention it in future docs?
The flow I plan to follow is that CI/CD will check if relevant files are mis-formatted, and throw an error if so. The user will need to format these files, whether through running make format-sql
, VSCode auto-formatter, etc.
sql/lanterndb.sql
Outdated
CREATE FUNCTION ldb_generic_dist (real[], real[]) | ||
RETURNS real | ||
AS 'MODULE_PATHNAME' | ||
LANGUAGE C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have the option of turning off pgFormatter
formatting for parts of the file (e.g. via a magic-comment.
e.g. in clang-format, any code I write within the magic comments below will not be formatted
// clang-format off
[CODE HERE]
// clang-format on
We should use a formatter that has such an option and should use such an option for sql statements that are very similar. This allows to more easily tell what is different between similar SQL statements.
For example, in the above, the two ldb_generic_dist
, and l2sq_dist
only differ in their argument types and that is easier to quickly verify visually when we have long "unformatted" sql lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-p | --placeholder RE : set regex to find code that must not be changed.
We could use this to achieve that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, great!
Let's do that for these kind of repeating statements.
sql/updates/0.0.1--0.0.2.sql
Outdated
AS 'MODULE_PATHNAME' LANGUAGE C; | ||
CREATE FUNCTION hnsw_handler (internal) | ||
RETURNS index_am_handler | ||
AS 'MODULE_PATHNAME' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a weak preference of not touching old update files. These are supposed to be immutable after the corresponding release. Formatting does not change the logic so not a big deal
Update pgFormatter doesn't support magic comment ignores well. (It keeps adding a space to the next line, for example). In addition, it doesn't support CTEs well either (multiple Github issues about this). I tried out pglast, which is based on libpg_query, which uses Postgres's parser. This handles all the Postgres SQL and pl/pgSQL corner cases nicely, but unfortunately doesn't handle the psql metacommands (e.g., \set \eqcho \copy) |
No description provided.