Write SQL in a sql-mode buffer and send it to a
Snowflake CLI
snow sql REPL running in a Ghostel
terminal buffer. The sql.el SQLi workflow, but with a real terminal
instead of comint, so the CLI's prompt_toolkit UI, paging and result
formatting all work natively.
M-x snowflake-connectstarts (or switches to) a REPL for any connection fromsnow connection list, one REPL buffer per connection. Called from asql-modebuffer it links that buffer to the REPL and enablessnowflake-minor-modein it.snowflake-minor-modeon top ofsql-modesends region, paragraph, statement, line, buffer or file to the linked REPL.- Registers a
snowflakesql.el product:SQL[Snowflake]mode line and highlighting for Snowflake keywords, types and functions on top of the ANSI ones. The minor mode switchessql-modebuffers to it automatically; opt out withsnowflake-set-sql-product. - Completion at point (works with corfu, company's capf backend or
plain
C-M-i): SQL keywords, Snowflake functions and types, plus the tables, views and schemas of the buffer's connection, fetched asynchronously via the CLI and cached per connection (snowflake-completion-fetch-trigger). Typingother_schema.fetches and completes that schema's objects (snowflake-completion-qualified). Column completion after table aliases is not supported. - Statements get a terminating
;appended when missing (snowflake-auto-terminate);!-commands like!queriesare left untouched. - Multi-line statements are sent via bracketed paste, single lines as keystrokes so they enter the REPL history naturally.
- SQL errors the REPL reports for sent statements are highlighted in
the source buffer: compilation errors with a
line L at position Plocation get a wave underline on the offending token, other errors underline the whole sent text; the full message is shown in the echo area and as tooltip on the highlight. Clear withsnowflake-clear-errors(C-c C-l) or by sending again; disable withsnowflake-highlight-errors, adapt the error detection withsnowflake-error-regexp. M-x snowflake-restartre-runssnow sqlin the same buffer after the CLI exits, e.g. when an auth token expired.M-x snowflaketransient menu with all commands.
(use-package snowflake
:vc (:url "https://github.com/dakra/snowflake.el" :rev :newest)
:hook (sql-mode . snowflake-minor-mode)
:custom
(snowflake-default-connection "dbb-dev"))snowflake-minor-mode shadows the comint-oriented sql.el bindings:
| Key | Command |
|---|---|
C-c C-c |
snowflake-send-paragraph |
C-c C-r |
snowflake-send-region |
C-c C-b |
snowflake-send-buffer |
C-c C-s |
snowflake-send-string |
C-c C-e |
snowflake-send-statement |
C-c C-n |
snowflake-send-line-and-next |
C-c C-f |
snowflake-send-file |
C-c C-z |
snowflake-switch-to-repl |
C-c C-j |
snowflake-set-buffer |
C-c C-k |
snowflake-interrupt |
C-c C-l |
snowflake-clear-errors |
All send commands accept a prefix argument to also select the REPL
window, except snowflake-send-file, where the prefix argument
prompts for the file instead; without it the window is displayed per
snowflake-display-repl-buffer-function (a function called with the
buffer, t for pop-to-buffer, or nil for no display — same
contract as sql-display-sqli-buffer-function).
snowflake-display-unless-visible displays the REPL only when it is
not already shown on some frame, e.g. on another monitor.
Unbound commands: snowflake-connect, snowflake-restart,
snowflake-refresh-connections, snowflake-refresh-completions,
snowflake (transient menu).
(setq snowflake-cli-program "snow" ; Snowflake CLI executable
snowflake-cli-extra-args nil ; extra args for `snow sql'
snowflake-default-connection nil ; nil = CLI default connection
snowflake-auto-terminate t ; append missing ";"
snowflake-highlight-errors t ; highlight REPL errors in the source
snowflake-error-regexp "^\\(?:Error occurred: \\)?\\([0-9]\\{6\\}\\) (\\([0-9A-Z]\\{5\\}\\)): " ; error header
snowflake-set-sql-product t ; switch buffers to the snowflake dialect
snowflake-completion t ; completion at point in the minor mode
snowflake-completion-fetch-trigger 'connect ; fetch objects on REPL link
snowflake-completion-object-scope 'schema ; complete the default schema's objects
snowflake-completion-qualified t ; schema.<TAB> completes that schema
;; #'display-buffer, t, nil or e.g. skip if on other monitor
snowflake-display-repl-buffer-function #'snowflake-display-unless-visible)
- For very large scripts prefer
snowflake-send-file(C-c C-f), which uses the REPL's!sourcecommand instead of pasting. - Error highlighting maps
line L at position Plocations relative to the first code token of the sent text — leading whitespace and comments don't count, matching how the CLI numbers statement lines. When several statements are sent at once the CLI reports lines per failing statement, so highlights for any statement but the first can land on the wrong line (the message shown is still correct).snowflake-send-stringandsnowflake-send-file(!source) don't highlight at all — their text has no buffer positions to map back to.
GPLv3