View Source Snowflex.Connection behaviour (Snowflex v0.5.2)
Defines a Snowflake connection.
Definition
When used, the connection expects the :otp_app
option. You may also define a standard timeout. This will default to 60 seconds.
If keep_alive?
is set to true
, each worker in the connection pool will
periodically send a dummy query to Snowflake to keep the authenticated
session from expiring.
defmodule SnowflakeConnection do
use Snowflex.Connection,
otp_app: :my_app,
timeout: :timer.seconds(60),
keep_alive?: true
end
Configuration should be extended in your config files.
# config/prod.exs
config :my_app, SnowflakeConnection,
size: [
max: 10,
min: 5
],
connection: [
server: "snowflex.us-east-8.snowflakecomputing.com",
role: "DEV",
warehouse: "CUSTOMER_DEV_WH"
]
The connection will default to using the Snowflex.Worker
module. You are able to define a different one for testing/development purposes in your configurations as well.
# config/dev.exs
config :my_app, SnowflakeConnection,
size: [
max: 1,
min: 1
],
worker: MyApp.MockWorker
Usage
Ensure the connection is started as part of your application.
defmodule MyApp.Application do
def start(_, _) do
...
children = [
...,
SnowflakeConnection
]
end
end
execute/1
query = "SELECT * FROM foo"
SnowflakeConnection.execute(query)
execute/2
query = """
SELECT * FROM foo
WHERE bar = ?
"""
SnowflakeConnection.execute(query, [Snowflex.string_param("baz")])
Link to this section Summary
Callbacks
Wraps Snowflex.sql_query/3
and injects the relevant information from the connection
Wraps Snowflex.param_query/4
and injects the relevant information from the connection
Link to this section Callbacks
Specs
execute(query :: String.t()) :: Snowflex.sql_data() | {:error, any()} | {:updated, integer()}
Wraps Snowflex.sql_query/3
and injects the relevant information from the connection
Specs
execute(query :: String.t(), params :: [Snowflex.query_param()]) :: Snowflex.sql_data() | {:error, any()} | {:updated, integer()}
Wraps Snowflex.param_query/4
and injects the relevant information from the connection