verticaleyes · 2022-02-03 08:12
verticaleyes · 2022-02-03 08:15
This is a very short video showcasing how I use org-mode for building SQL queries in my web projects; something for which I used to add pgadmin as a docker container earlier.
For anyone interested, there is a blog post which goes into more details, and also into how I set it up: https://bitspook.in/blog/using-org-mode-as-an-sql-playground/
You can find me using this in a small open-source side project of mine here: https://github.com/bitspook/entropy/tree/96cc9c0485d972ed819996d61c3730cafb228660
verticaleyes · 2022-02-03 09:36
I think I'll be able to make a few more videos before the rush of making videos wears out. I share the youtube link here so it'd be easier for you guys to quickly view the video and decide whether it is worth your time. Please do let me know if you'd prefer me sharing the blog post in the link here instead.
discursive_moth · 2022-02-03 14:44
I really like Org-mode and SQL mode for (ms) SQL, but I'm missing good completions for databases/schemas/tables/columns. I tried sqls with LSP mode, but couldn't get completions for databases on the server other than my user's default database.
AndreaSomePostfix · 2022-02-03 15:21
Indeed, u/verticaleyes how difficult was to configure lsp-org to get your autocompletion? I struggled with it as well! Any chance you could share some tips?
verticaleyes · 2022-02-03 15:45
Configuring lsp-org for SQL src blocks was easy; but configuring it for edit buffers (pressing `C-c '`) was impossible in the time I could spare for it. LSP for SQL using SQLS itself is finicky; it sometimes just refuses to work. Even in the video you can notice the column names auto-completion didn't show up for first 2 columns. Also everytime something went wrong with LSP setup (e.g me shutting down the LSP server), I had to close the sql-playground.org file and re-open it just to get lsp start properly again.
You can take a look at the [blog post](https://bitspook.in/blog/using-org-mode-as-an-sql-playground/) where I've listed everything I did to set it up. If you want to take a look at how I am setting up lsp-mode itself, you can check it [here](https://github.com/bitspook/spookmax.d/blame/18f89e2ac15c227af12064846e00fcb2f764f860/readme.org#L999-L1023) (spoiler: it's quite vanilla).
paretoOptimalDev · 2022-02-03 21:39
I think I had both working?
I at least have source block completion, i'll check if both are.
verticaleyes · 2022-02-04 05:08
Will be great if you can share how you got the lsp support in edit buffers (I hope I am using the right term here; the buffer you get by pressing `C-c '` in org src block). I gave up on that with the conclusion that lsp-mode's headerline-breadcrumbs can't be disabled locally. This is what it throws at me when I attempt to start lsp-mode in an edit buffer:
```
lsp-headerline-breadcrumb-mode: Wrong type argument: listp, #("Edit, then exit with ‘C-c '’ or abort with ‘C-c C-k’" 22 27 (face help-key-binding font-lock-face help-key-binding) 44 51 (face help-key-binding font-lock-face help-key-binding))
```
hubisan-one · 2022-02-04 13:24
To enable LSP in edit buffers use the snippet from that [issue](https://github.com/emacs-lsp/lsp-mode/issues/2842#issuecomment-870807018) on github. It also requires you to set the tangle header keyword.
Add this function to your init or evaluate it in your current session (rewrote it to not depend on dash):
(defun org-babel-edit-prep:sql (babel-info)
(setq-local buffer-file-name (alist-get :tangle (caddr babel-info)))
(lsp))
To enable LSP in the edit buffer add the tangle header keyword:
#+BEGIN_SRC sql :tangle path/filename.sql
...
#+END_SRC