Skip to main content

Better stored procedure management

Project description

Contributors Forks Stargazers Issues LinkedIn


⚙️ 🚀

Sprocketship

Better stored procedure management

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. License

About The Project

sprocketship makes it easy to develop, manage, and deploy stored procedures in Snowflake. Using the language of your choosing, you can write the contents of your stored procedure separately from its configurations (e.g., EXECUTE AS, RETURN TYPE, etc.).

Built With

(back to top)

Getting Started

Installation

pip install sprocketship

Usage

Structure

Currently, sprocketship expects a .sprocketship.yml file in a procedures/ directory.

├── dbt_models
│   ├── customers.sql
│   ├── products.sql
├── procedures
│   ├── useradmin
│   │   ├── create_database_writer_role.js
│   │   ├── create_database_reader_role.js
│   ├── sysadmin
│   │   ├── create_temp_database.js
└── .sprocketship.yml

The yaml path to each procedure in the sprocketship.yml should follow that of the paths to their corresponding files in the procedures/ directory.

procedures:
  development:
    - name: create_temp_database
      database: !env_var SNOWFLAKE_DATABASE
      schema: !env_var SNOWFLAKE_SCHEMA
      ...

  admin:
    - name: create_database_reader
      database: !env_var SNOWFLAKE_DATABASE
      schema: !env_var SNOWFLAKE_SCHEMA
      ...

    - name: create_database_writer
      database: !env_var SNOWFLAKE_DATABASE
      schema: !env_var SNOWFLAKE_SCHEMA
      ...

Directory-level Default Parameters

sprocketship allows providing default parameters at any given level of your project. These defaults will be applied recursively to any procedures defined in any of the subdirectories, unless overridden by a default in one of the subdirectories.

procedures:
  # for all procedures, default to the below database and schema
  +database: !env_var SNOWFLAKE_DATABASE
  +schema: !env_var SNOWFLAKE_SCHEMA
  development:
    # for all procedures in the development directory,
    # default to using the sysadmin role
    +use_role: sysadmin
    create_temp_database:
      args:
        - name: Name of argument
          type: Type of argument
          default: (Optional) default value for the argument
      returns: varchar

File Frontmatter

Thanks to ABSQL, sprocketship also provides the ability to define parameters using file frontmatter. Suppose we have a file create_database_writer_role.js, we can define parameters for the stored procedure within the file using frontmatter:

/*
database: my_database
schema: my_schema
language: javascript
execute_as: owner
use_role: sysadmin
*/

sprocketship will automatically parse and apply the parameters defined in the frontmatter to the stored procedure.

Recommended Configuration

When setting up your sprocketship project, we recommend setting more general parameters (e.g., database, schema, language, etc.) in the .sprocketship.yml file, and anything that's specific to a given procedure should be defined in the file frontmatter of that procedure, such as the args or return type.

Execution

From here, simply run

$ sprocketship liftoff

from the project directory (or provide the directory, e.g. sprocketship liftoff my/directory/path) and sprocketship will launch your stored procedures into the given directory.

Exhaustive Options for Stored Procedure Configuration

database: The name of the database where the procedure will be stored
schema: The name of the schema where the procedure will be stored
language: The language of the procedure definition
execute_as: caller or owner
use_role: The role you'd like to own the procedure
args:
    - name: Name of argument
      type: Type of argument
      default: (Optional) default value for the argument
returns: The return type, this can include the `NOT NULL` option
comment: Explanation of the procedure

Support

sprocketship currently only supports Javascript-based stored procedures (Python support coming soon!). Additionally, there are a few options from the CREATE STORED PROCEDURE function that are not yet supported:

  • CALLED ON NULL INPUT | { RETURNS NULL ON NULL INPUT | STRICT }
  • VOLATILE | IMMUTABLE (deprecated)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sprocketship-1.0.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

sprocketship-1.0.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file sprocketship-1.0.2.tar.gz.

File metadata

  • Download URL: sprocketship-1.0.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sprocketship-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c5e7eb82170aaf91f3f2a49345fccc0dd0039292d4bf7e3deaf2c69985dd67b1
MD5 dced9494b369a2498808a817376c23db
BLAKE2b-256 ab7e96014fcbbc52146c963e3858338bcdd2d05c5a2d707cca686da70a97df65

See more details on using hashes here.

File details

Details for the file sprocketship-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: sprocketship-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sprocketship-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8b15cc2cc2aead23c9ba4ef5c5b321b9fd4d9526e597ef031f7a26302198d37d
MD5 086e038dfbfd7089b6c41307dbc6c8f1
BLAKE2b-256 506ce3ba56c04d1283d424ad0e7729483e726b018a313ece7eec67661e2fc758

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page