Skip to content

Basic SQL script support - #8

Draft
MMagueta wants to merge 3 commits into
emarsden:mainfrom
MMagueta:add-script-support
Draft

Basic SQL script support#8
MMagueta wants to merge 3 commits into
emarsden:mainfrom
MMagueta:add-script-support

Conversation

@MMagueta

@MMagueta MMagueta commented Nov 19, 2024

Copy link
Copy Markdown

Context

Most of the tools for interacting with Postgres on Emacs usually do not format the tables properly and lack that interactive feel of a Lisp Machine. I think this project is the perfect candidate for that!

Screencast From 2024-11-18 23-45-02

Scope

Here I try to implement a script interface where you can either open or type your own SQL queries in a buffer, and eval specifically the ones you selected, without copying and pasting on the minibuffer, or having it all by itself on a buffer via e and E.

How it is implemented

I made a new mode called pgmacs-script-mode that is a minor mode of a buffer with its major mode as sql-mode. Then I made an action called pgmacs--script that passes over the local variables to the script buffer.

The main limitation I found to open arbitrary files would be passing over the local variables. Using (sql-mode) instead of (pgmacs-script-mode) in pgmacs--script simply overrides the connection, so it seems like I need an extension of pgmacs-mode. I also wanted to experiment with lsp-mode and how it behaves using the same connection.

Notes

  • Please do provide criticism if the feature is desirable and if we should redesign the idea. I would be very eager to have it properly implemented;
  • I still have not finished documenting as I don't know if the idea is sound.

@MMagueta

Copy link
Copy Markdown
Author

@emarsden could you please share your input here? I would like to know if you want this feature in your package, and if so, what would be the way forward with this?

Also, great work so far. I am very glad you started this effort

@emarsden

Copy link
Copy Markdown
Owner

This looks like a useful feature, thanks.

I think you could implement pgmacs-run-sql-region and perhaps pgmacs-run-buffer-sql to also work in a random buffer (opened with find-file). Add a global variable pgmacs--connections to which the pgmacs--con buffer-local variable is added whenever a new PGmacs connection is created. In pgmacs-run-sql-region & friends, ask the user which connection to use if the list pgmacs--connections contains more than a single element.

Probably the underlying pgmacs-run-sql should behave in a nicer manner for SQL that returns an empty row set.

@MMagueta

Copy link
Copy Markdown
Author

I haven't had much time to play around with this. I'm probably doing it on the weekend

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