Skip to content

greshny/ob-snowflake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

ob-snowflake

Org Babel support for running Snowflake SQL blocks through the Snowflake CLI.

Requirements

  • Emacs 27.1 or newer
  • Org 9.5 or newer
  • Snowflake CLI available as snow
  • A configured Snowflake CLI connection

This package does not manage Snowflake credentials. Configure authentication and connections with the Snowflake CLI.

Snowflake CLI

Install Snowflake CLI with Homebrew:

brew tap snowflakedb/snowflake-cli
brew update
brew install snowflake-cli
snow --help

Official Snowflake CLI documentation:

Snowflake CLI reads connections from config.toml. If ~/.snowflake exists, the default file is ~/.snowflake/config.toml. Otherwise, on macOS the default file is ~/Library/Application Support/snowflake/config.toml. You can also use --config-file or SNOWFLAKE_HOME.

Example ~/.snowflake/config.toml:

default_connection_name = "default"

[connections.default]
account = "myorganization-myaccount"
user = "jdoe"
role = "ANALYST"
warehouse = "COMPUTE_WH"
database = "EXAMPLE_DB"
schema = "PUBLIC"
authenticator = "EXTERNALBROWSER"

On macOS and Linux, Snowflake CLI requires the configuration file to be readable and writable only by the owner:

chmod 0600 ~/.snowflake/config.toml

Test the connection before using it from Org:

snow connection test --connection default
snow sql --connection default -q "select current_user(), current_role(), current_warehouse();"

Installation

With straight.el and use-package:

(use-package ob-snowflake
  :straight (:host github :repo "greshny/ob-snowflake")
  :after org
  :config
  (require 'ob-snowflake))

With Emacs 30 or newer, use the built-in package-vc integration through use-package :vc:

(use-package ob-snowflake
  :vc (:url "https://github.com/greshny/ob-snowflake"
       :rev :newest)
  :after org
  :config
  (require 'ob-snowflake))

ob-snowflake expects Org/Babel to be available from Emacs or from the user’s existing Org installation. It does not force installation of a separate Org package.

Usage

Evaluate snowflake source blocks from Org:

#+begin_src snowflake :connection default :database EXAMPLE_DB :schema PUBLIC :results output
select current_user(), current_role(), current_warehouse();
#+end_src

Supported header arguments:

  • :connection - Snowflake CLI connection name
  • :role - role override
  • :warehouse - warehouse override
  • :database - database override
  • :schema - schema override
  • :format - Snowflake CLI output format, for example TABLE, JSON, JSON_EXT, or CSV

Configuration

(setq ob-snowflake-default-connection "default"
      ob-snowflake-default-format "TABLE")

License

MIT

About

Org Babel support for running Snowflake SQL blocks through the Snowflake CLI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors