Snowflex.Transport behaviour (Snowflex v1.7.2)

View Source

Behaviour module that defines the interface for Snowflake transport implementations.

See Snowflex.Transport.Http for the default implementation.

Summary

Callbacks

Request cancellation of a previously submitted statement.

Clean up cursor state after streaming is complete. See DBConnection.handle_deallocate/4 for more information.

Declare a statement (primarily for streaming) and return a cursor. See DBConnection.handle_declare/4 for more information.

Disconnect from the database. See DBConnection.handle_close/3 for more information.

Execute a statement. See DBConnection.handle_execute/4 for more information.

Fetch the next result from a cursor. Return {:ok, result} while the cursor may still hold more results and {:halt, result} once it is exhausted. See DBConnection.handle_fetch/4 for more information.

Fetch the result of a previously submitted statement.

Periodic pings to the server, default is once per second. See DBConnection.ping/1 for more information.

Report the status of a previously submitted statement.

Submit a statement for execution and return as soon as the server acknowledges it, without waiting for the statement to finish.

Types

connection_opts()

@type connection_opts() :: Keyword.t()

cursor()

@type cursor() :: term()

fetch_result()

@type fetch_result() ::
  {:ok, Snowflex.Result.t()}
  | {:halt, Snowflex.Result.t()}
  | {:error, Snowflex.Error.t()}

query_result()

@type query_result() :: {:ok, Snowflex.Result.t()} | {:error, Snowflex.Error.t()}

status_result()

@type status_result() :: {:ok, :running | :succeeded} | {:error, Snowflex.Error.t()}

Callbacks

cancel_statement(pid, t, t)

(optional)
@callback cancel_statement(pid(), String.t(), Keyword.t()) :: query_result()

Request cancellation of a previously submitted statement.

deallocate(pid)

@callback deallocate(pid()) :: :ok

Clean up cursor state after streaming is complete. See DBConnection.handle_deallocate/4 for more information.

declare(pid, t, any, t)

@callback declare(pid(), String.t(), any(), Keyword.t()) ::
  {:ok, cursor()} | {:error, Snowflex.Error.t()}

Declare a statement (primarily for streaming) and return a cursor. See DBConnection.handle_declare/4 for more information.

disconnect(pid)

@callback disconnect(pid()) :: :ok

Disconnect from the database. See DBConnection.handle_close/3 for more information.

execute_statement(pid, t, any, t)

@callback execute_statement(pid(), String.t(), any(), Keyword.t()) :: query_result()

Execute a statement. See DBConnection.handle_execute/4 for more information.

fetch(pid, cursor, t)

@callback fetch(pid(), cursor(), Keyword.t()) :: fetch_result()

Fetch the next result from a cursor. Return {:ok, result} while the cursor may still hold more results and {:halt, result} once it is exhausted. See DBConnection.handle_fetch/4 for more information.

fetch_result(pid, t, t)

(optional)
@callback fetch_result(pid(), String.t(), Keyword.t()) ::
  {:ok, Snowflex.Result.t() | :running} | {:error, Snowflex.Error.t()}

Fetch the result of a previously submitted statement.

Returns {:ok, :running} if the statement has not finished yet, so a caller can poll with this function alone. Once the statement has completed the full result set is returned as {:ok, t:Snowflex.Result.t/0}.

ping(pid)

@callback ping(pid()) :: query_result()

Periodic pings to the server, default is once per second. See DBConnection.ping/1 for more information.

start_link(connection_opts)

@callback start_link(connection_opts()) :: GenServer.on_start()

statement_status(pid, t, t)

(optional)
@callback statement_status(pid(), String.t(), Keyword.t()) :: status_result()

Report the status of a previously submitted statement.

Returns {:ok, :running} while the statement is executing and {:ok, :succeeded} once it has finished successfully. A statement that finished with an error is reported as {:error, t:Snowflex.Error.t/0}.

submit_async(pid, t, any, t)

(optional)
@callback submit_async(pid(), String.t(), any(), Keyword.t()) :: query_result()

Submit a statement for execution and return as soon as the server acknowledges it, without waiting for the statement to finish.

The returned Snowflex.Result.t/0 carries the server's statement handle in :query_id; it has no rows. Use statement_status/3 to check on the statement later and cancel_statement/3 to stop it.