DEV Community

jreighley
jreighley

Posted on

5 2

Dynamic SQL cheatsheet

I have been writing a lot of my own IBMi diagnostic tools lately using Clojure and ClojureScript.

One of the problems I often encounter is needing to track down some data without having a great understanding of the tables and data I am querying.. So I built this tool to help me build queries.

sqlbuilder-image

When I select a machine, it selects a default schema and gives me a list of all possible tables. I select a table and press 'Get Sample' and it fetches me the 'Select * FROM table Limit 5' and displays the results. This is very helpful in that I can see the field names as well the format used for the data in each field. Sometimes my 5 samples don't give me enough information. Perhaps all five samples have the same value in a field or no value at all. I added a sample button in each row to help me with this case. When it is pressed, it fetches me the first five 5 distinct values from that field. Does this customer use this field at all? Is it what I think it is? Answers are often a click away.

At the bottom of the sample, I have a textbox in which I can type a SQL query. It's much easier now that I have a dynamically generated cheat sheet that gives me hints for any table.

It is already very helpful. Questions like "what date format" are no longer guesswork.

I plan to enhance it by having it suggest joins for me. I also plan to have it save queries for future use, and have it suggest those queries when a particular table is selected. I may add full interactive SQL capabilities to it. Time will tell.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay