pepsico-ecommerce / snowflex

elixir snowflake client
Apache License 2.0
52 stars 10 forks source link

feature(snowflex): Use database when connecting. #57

Closed DaliborHorinek closed 2 years ago

PM-Pepsico commented 2 years ago

After digging in a bit more into how the Snowflake ODBC connection works it turn out you can pass a database and schema as optional connection parameters, https://docs.snowflake.com/en/user-guide/odbc-parameters.html#optional-connection-parameters.

Based on how we pass all of the variables set as options on the connection as parameters in the connection string, this means you can set these values just by putting them as options in the connection list when you configure the repo like so:

config :test_app, TestApp.Repo,
  connection: [
    authenticator: "SNOWFLAKE_JWT",
    priv_key_file: System.get_env("SNOWFLAKE_PRIV_KEY_FILE"),
    uid: System.get_env("SNOWFLAKE_USER_ID"),
    warehouse: System.get_env("SNOWFLAKE_WAREHOUSE"),
    role: System.get_env("SNOWFLAKE_ROLE"),
    server: System.get_env("SNOWFLAKE_SERVER"),
    database: System.get_env("SNOWFLAKE_DATABASE"),
    schema: System.get_env("SNOWFLAKE_SCHEMA")
  ]