sinker 2 days ago

I've started using Emacs as a database explorer.

So, Emacs has a built-in interactive SQL mode (M-x sql-mysql / postgres / sqlite). This mode opens a SQL shell similar to what you would see in a terminal. From there, you can do your selects, inserts, updates, etc.

You can also send strings from a different buffer to your SQL shell buffer.

Now in Emacs you can very easily evaluate Lisp code to define functions, redefine functions, and execute arbitrary expressions. You can also wrap your SQL expressions inside of Lisp code. By doing so, you can take advantage of Emacs's built-in Lisp evaluation tools to interact with your SQL database.

So instead of opening a shell in your terminal, selecting a database, and writing select statements to inspect your DB, you can instead...

In Emacs, create a file called something like "sql-notebook.el". Inside that file you write Lisp expressions to execute SQL queries. To execute those queries, you move the cursor over it and just run the command `eval-last-expr` (I have this bound to Ctrl-c Ctrl-c). The results of the evaluated expressions appear in your interactive SQL buffer.

The obvious advantage of this is that you end up creating a library of often-used queries which are very convenient to execute simply by moving the cursor over the query and hitting Ctrl-c twice.

You also retain a history of these queries by virtue of them existing in a plain file, as opposed to ephemeral shell history.

  • maverick98 2 days ago

    hey thats pretty cool, I will try to see how that works, I didn't know it. But it sounds like a lot of work to set it up. I wanted to make something faster

    • sinker 2 days ago

      It's not a lot of work, but it takes a little bit of existing Elisp knowledge. You can still evaluate plain SQL code in a buffer (sql-mode) and get most of the benefits I described, you just won't get the convenience of evaluating Lisp forms.

dotancohen 2 days ago

This might be a great tool, but the demo is horrible. The gif slowly builds up to something interesting, showing the setup of the tool. But then when it gets to showing the output, the gif resets back to the beginning. What does the tools actually provide?

Instead of a gif, please just paste that output into code fences in the README file.

Petros_S 2 days ago

Cool tool, are you planning to support also other kind of DBs that are NoSQL such as MongoDB or Redis? That would be really interesting too.

  • maverick98 2 days ago

    yeah its planned for the next release!

    • otherayden 2 days ago

      I would be very interested in mondodb support, mongodb has an official inspector tool but it’s such a memory hog that it sometimes crashes my laptop

      • maverick98 2 days ago

        We will add this too thanks for the suggestion

maverick98 3 days ago

While working on other projects, I found myself always having to connect and use SELECT * to see dummy entries or new users. I favored the CLI for monitoring my database entries, especially because I was testing and just adding dummy users + our first normal users in projects. So it became a bit tiring always having to connect to postgres, mysql and give select * queries from the CLI.

  • Aherontas 2 days ago

    Support via UI, will also be something interesting.How did you come up with this idea in general(I am curious)?

blumomo 2 days ago

Cool approach!

This tool appeals to me as someone who is already familiar to pgcli, psql, mysql, etc. Typing every time SELECT * FROM… annoys me, too.

I’d prefer to already evaluate the tool in the first or second paragraph. If you could move the readme section with the most eye opening and time saving commands right after the video, that would be great.

Thanks for making and sharing this tool.

  • maverick98 2 days ago

    Hello thanks a lot for the kind words! I will make note to fix the README for sure and add some examples too, it is an open issue

Levi_Hackerman 2 days ago

This seems really cool! Looking forward to any updates on it.

  • maverick98 2 days ago

    hey! thanks a lot! Updates will be up very soon

Zaloog 2 days ago

How does this compare to Harlequin?

  • maverick98 2 days ago

    I started this with the focus being on speed set it up run thencommand and see the output. Harlequin seems to have a bit more hassle. We d also like to add a gui at some point if the user wants to open it on browser