mysqlex v0.0.2 Mysqlex.Connection
Main API for Mysqlex. This module handles the connection to .
Link to this section Summary
Functions
Runs an (extended) query and returns the result as {:ok, %Mysqlex.Result{}}
or {:error, %Mysqlex.Error{}} if there was an error. Parameters can be
set in the query as ? embedded in the query string. Parameters are given as
a list of elixir values. See the README for information on how Mysqlex
encodes and decodes elixir values by default. See Mysqlex.Result for the
result data
Runs an (extended) query and returns the result or raises Mysqlex.Error if
there was an error. See query/3
Start the connection process and connect to mariadb
Stop the process and disconnect
Link to this section Functions
query(pid(), iodata(), list(), Keyword.t()) :: {:ok, Mysqlex.Result.t()} | {:error, Mysqlex.Error.t()}
Runs an (extended) query and returns the result as {:ok, %Mysqlex.Result{}}
or {:error, %Mysqlex.Error{}} if there was an error. Parameters can be
set in the query as ? embedded in the query string. Parameters are given as
a list of elixir values. See the README for information on how Mysqlex
encodes and decodes elixir values by default. See Mysqlex.Result for the
result data.
A type hinted query is run if both the options :param_types and
:result_types are given. One client-server round trip can be saved by
providing the types to Mysqlex because the server doesn’t have to be queried
for the types of the parameters and the result.
Options
:timeout- Call timeout (default:5000):param_types- A list of type names for the parameters:result_types- A list of type names for the result rows
Examples
Mysqlex.Connection.query(pid, "CREATE TABLE posts (id serial, title text)")
Mysqlex.Connection.query(pid, "INSERT INTO posts (title) VALUES ('my title')")
Mysqlex.Connection.query(pid, "SELECT title FROM posts", [])
Mysqlex.Connection.query(pid, "SELECT id FROM posts WHERE title like ?", ["%my%"])
Mysqlex.Connection.query(pid, "SELECT ? || ?", ["4", "2"],
param_types: ["text", "text"], result_types: ["text"])
Runs an (extended) query and returns the result or raises Mysqlex.Error if
there was an error. See query/3.
start_link(Keyword.t()) :: {:ok, pid()} | {:error, Mysqlex.Error.t() | term()}
Start the connection process and connect to mariadb.
Options
:hostname- Server hostname (default: MDBHOST env variable, then localhost);:port- Server port (default: 3306);:sock_type- Socket type (default: :tcp);:database- Database (required);:username- Username (default: MDBUSER env variable, then USER env var);:password- User password (default MDBPASSWORD);:parameters- Keyword list of connection parameters;:queries- A list of queries to run on startup, set timezone, etc.:timeout- Connect timeout in milliseconds (default: 5000);:socket_options- Options to be given to the underlying socket;:charset- Database encoding (default: “utf8”); # TODO - Copied from mariaex, not sure if this should be ‘utf8’ or ‘utf8mb4’ # or if we should even set a default encoding at all
Stop the process and disconnect.