View Source Spannex (spannex v0.5.0)

The entry module for interacting with Spannex.Protocol, the underlying DBConnection implementation.

To create a Spannex database connection to Cloud Spanner, simply call Spannex.start_link/1 with the database configuration or pass in {Spannex, opts} to your supervisor.

Queries vs Mutations

Spanner makes a clear distinction between "queries", which are read-only statements, and "mutations", which are statements that modify the state of the database. However, Spannex still provides a single function, execute/4, and will perform any necessary internal conversions depending on the type of the statement being executed.

Named Variables

Currently, only named variables are accepted in queries and mutations. You must also pass in a map of named variables when executing a statement that contains named variables. For example, if you have a query like SELECT * FROM users WHERE id = @id, you must pass in a map containing %{id: 1} when executing the statement.

Summary

Functions

Returns a child specification for the Spannex database connection using the given options.

Converts a string SQL statement into a Spannex.Query struct before calling DBConnection.prepare_execute/4.

Starts a Spannex database connection using the given options.

Runs the given function inside a Spanner transaction.

Functions

Returns a child specification for the Spannex database connection using the given options.

You must supply at least one option, :database, to specify the Cloud Spanner database to connect to.

It is recommended to avoid supplying the :name option and to instead let the connection pool handle fetching and returning individual connections.

See Spannex.Protocol.connect/1 for a full list of accepted options.

Link to this function

execute(conn, statement, params, opts \\ [])

View Source

Converts a string SQL statement into a Spannex.Query struct before calling DBConnection.prepare_execute/4.

Starts a Spannex database connection using the given options.

Synonymous with DBConnection.start_link(Spannex.Protocol, opts).

You must supply at least one option, :database, to specify the Cloud Spanner database to connect to.

See Spannex.Protocol.connect/1 for a full list of accepted options.

Link to this function

transaction(conn, fun, opts \\ [])

View Source

Runs the given function inside a Spanner transaction.