Skip to content
This repository has been archived by the owner on May 20, 2019. It is now read-only.

Commit

Permalink
Rename :socket to :socket_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Jan 25, 2018
1 parent 69f7860 commit d3ddd3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/postgrex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ defmodule Postgrex do
## Options
* `:hostname` - Server hostname (default: PGHOST env variable, then localhost);
* `:socket` - The socket to connect to (takes precedence over the hostname);
* `:socket_dir` - Connect to Postgres via UNIX sockets in the given directory
(takes precedence over the hostname);
* `:port` - Server port (default: PGPORT env variable, then 5432);
* `:database` - Database (default: PGDATABASE env variable; otherwise required);
* `:username` - Username (default: PGUSER env variable, then USER env var);
Expand All @@ -47,7 +48,8 @@ defmodule Postgrex do
(defaults to `:timeout` value);
* `:ssl` - Set to `true` if ssl should be used (default: `false`);
* `:ssl_opts` - A list of ssl options, see ssl docs;
* `:socket_options` - Options to be given to the underlying socket;
* `:socket_options` - Options to be given to the underlying socket
(applies to both TCP and UNIX sockets);
* `:prepare` - How to prepare queries, either `:named` to use named queries
or `:unnamed` to force unnamed queries (default: `:named`);
* `:transactions` - Set to `:strict` to error on unexpected transaction
Expand Down Expand Up @@ -75,7 +77,7 @@ defmodule Postgrex do
Connect to postgres instance through a unix domain socket
iex> {:ok, pid} = Postgrex.start_link(socket: "/tmp", database: "postgres")
iex> {:ok, pid} = Postgrex.start_link(socket_dir: "/tmp", database: "postgres")
{:ok, #PID<0.69.0>}
## PgBouncer
Expand Down
4 changes: 2 additions & 2 deletions lib/postgrex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Postgrex.Protocol do
port = opts[:port] || 5432

{host, port} =
case Keyword.fetch(opts, :socket) do
case Keyword.fetch(opts, :socket_dir) do
{:ok, socket} ->
{{:local, "#{socket}/.s.PGSQL.#{port}"}, 0}

Expand All @@ -64,7 +64,7 @@ defmodule Postgrex.Protocol do
{to_charlist(hostname), port}

:error ->
raise ArgumentError, "expected :hostname or :socket to be given"
raise ArgumentError, "expected :hostname or :socket_dir to be given"
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/login_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ defmodule LoginTest do
test "unix domain socket connection", context do
socket = System.get_env("PG_SOCKET_DIR") || "/tmp"

opts = [socket: socket]
opts = [socket_dir: socket]
capture_log fn ->
assert {:ok, pid} = P.start_link(opts ++ context[:options])
assert {:ok, %Postgrex.Result{}} = P.query(pid, "SELECT 123", [])
Expand All @@ -154,7 +154,7 @@ defmodule LoginTest do
@tag :unix
test "non-existent unix domain socket", context do
Process.flag(:trap_exit, true)
opts = [socket: "/doesntexist"]
opts = [socket_dir: "/doesntexist"]

capture_log fn ->
assert {:ok, pid} = P.start_link(opts ++ context[:options])
Expand Down

0 comments on commit d3ddd3f

Please sign in to comment.