Skip to content
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

Enhance sqlpath.Glob to actually support glob wildcard #2955

Merged
merged 6 commits into from
Nov 14, 2023

Conversation

iamwavecut
Copy link
Contributor

This PR enhances the Glob function in the internal/sqlpath package to support glob patterns in the input paths. It also adds comprehensive tests for the Glob function, ensuring its correct behavior and in various scenarios, as well as protects it from regressions.

Problem

I want sqlc to be able to collect queries from different modules of my applications:

...
sql:
  - engine: "postgresql"
    queries: "modules/*/sql"
...

Epected:

Normal execution.

Actual:

error parsing queries: path /home/masked/project/internal/modules/*/sql does not exist
  • internal/sql/sqlpath/read_test.go: Introduced a new test file with multiple test cases for the Glob function. These tests cover various scenarios like handling of SQL files, non-SQL files, hidden files, non-existent paths, unreadable directories, and symlinks.

  • internal/sql/sqlpath/read.go: Added a new function expandGlob s to expand glob patterns in the input paths. The Glob function now calls expandGlob s before processing the paths. Also, added error handling for cases where the path does not exist or is not a file.

  • internal/sql/sqlpath/testdata/: Dummy directory of files and symlinks to test various scenarios.

@iamwavecut
Copy link
Contributor Author

@sqlc-dev please take a look

@kyleconroy kyleconroy changed the title Enhance sqlpath.Glob to actually support glob wildcart. Enhance sqlpath.Glob to actually support glob wildcard Nov 7, 2023
@kyleconroy
Copy link
Collaborator

@iamwavecut I made a few changes to the PR. I remove the nolint comment, as we don't use those anywhere in the codebase. I only call filepath.Glob if the path contains ?*[]. It's easier to preserve existing behavior this way.

I also changed the error messages to include the info from os.Stat. This information isn't as useful as the results from lstat, but it is more consistent across platforms.

@iamwavecut
Copy link
Contributor Author

@kyleconroy Sure! Thanks for the improvements.

@iamwavecut
Copy link
Contributor Author

Is there a chance that I'll see this released anytime soon? @kyleconroy

@kyleconroy kyleconroy merged commit 13141d9 into sqlc-dev:main Nov 14, 2023
8 checks passed
@kyleconroy
Copy link
Collaborator

@iamwavecut This will be released in 1.24.0 sometime next week.

@iamwavecut iamwavecut deleted the sqlpath-glob-enhancement branch November 14, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants