Skip to content

Add saved query management functions.#191

Open
sfc-gh-jsoyland wants to merge 3 commits into
mainfrom
jsoyland/manage_saved_queries
Open

Add saved query management functions.#191
sfc-gh-jsoyland wants to merge 3 commits into
mainfrom
jsoyland/manage_saved_queries

Conversation

@sfc-gh-jsoyland
Copy link
Copy Markdown
Collaborator

No description provided.

@sfc-gh-jsoyland sfc-gh-jsoyland requested a review from a team as a code owner May 4, 2026 16:06
Linter didn't like:
```
       > src/cb/saved_query.cr:95:29
       > [W] Lint/NotNil: Avoid using `not_nil!`
       > > name:         @name.not_nil!,
```

So removed the `not_nil!`.  It is now consistent with other
functions in the existing code base by not type-annotating
client method parameters
@sfc-gh-jsoyland
Copy link
Copy Markdown
Collaborator Author

Tried a 3-phased approach to this PR with checkpoints that I could review. I also found that it made the process repeatable on a fresh branch.

  1. First asked Claude to research how to best apply a new function by reviewing existing code and API documentation. Then to persist findings to 01-research.md for review.

  2. Asked Claude to plan what changes would be needed based on findings from the research document: 02-planning.md

  3. Asked Claude to produce a testing plan for review post-implementation. That way I could review the doc and make sure that it wasn't trying to cheat in it's success criteria: 03-testing.md

Once artifacts were generated, started a new session and asked Claude to implement changes. Everything generated/passed on the first pass, save for the linter error.

Copy link
Copy Markdown
Collaborator

@sfc-gh-abrightwell sfc-gh-abrightwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a few comments.

Comment thread src/cb/saved_query.cr
query = client.get_saved_query query_id

filename = @file || "#{query.name.gsub(/[^a-zA-Z0-9_\-]/, "_")}.sql"
File.write(filename, query.sql)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have a rescue block in case this fails so that the user gets an error message over a stack trace?

Comment thread src/cb/saved_query.cr

def run
validate
sql = File.read(@file.to_s)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here maybe, if the file doesn't exist?

Spitballing, but could maybe do something like:

unless File.exists?(@file.to_s) <some error>?

Maybe crystal does something reasonable though if not? Maybe worth validating? 🤷‍♂️

end

it "exports to specified file" do
action.file = "/tmp/test_export.sql"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth considering using Dir.tempdir? As it abstracts the system tempdir which I think is /var/folders on macos and /tmp on Linux... 🤔

Comment thread src/client/saved_query.cr
CB::Model::SavedQuery.from_json resp.body
end

def create_saved_query(params)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth definite a param type for the create method. As I think that leaving it unbounded chokes spectator when generating the mock client. Or at least that's one thing I feel like eased the CI failures a little that I was debugging in #192.

    struct SavedQueryCreateParams
      include JSON::Serializable
      property cluster_id : String?
      property name : String?
      property sql : String?
      property? skip_enqueue : Bool = true

      def initialize(@cluster_id, @name, @sql, @skip_enqueue = true)
      end
    end

    def create_saved_query(params : SavedQueryCreateParams)
      resp = post "saved-queries", params
      CB::Model::SavedQuery.from_json resp.body
    end

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