Wednesday, April 27, 2016

Postgres + Erlang on OS X Part 1

I've been trying to get epgsql so I can build out the database for Markov-lang.  Getting this running took some time.

First we needed to install rebar3.  You do this by running:
brew install homebrew/versions/rebar3
Once rebar3 is installed, you have to configure it to work with  You do this by running the following:
mkdir -p ~/.config/rebar3 
Then create the following file ~/.config/rebar3/rebar.config with the following contents:
 {plugins, [rebar3_hex]}.
(EDIT: According to Reddit user mononcqc this is only necessary if you want to publish packages not fetch them)

Then run:
rebar3 update

Now, in the directory for you project that will use postgres, create a file /Path/To/App/rebar.config with the following content:
{deps, [epgsql]}.
Now you can access epgsql by running:
rebar3 shell
It should compoile epgsql. In the REPL started by the previous command you can run:
To access this from within Emacs, start the Erlang REPL in Emacs with the following flag:
-pz _build/default/deps/epgsql/ebin 

Part 2 can be found here.


  1. Really helpful.
    I think there is a typo `rebar3s shell` should be `rebar3 shell`.
    Instruction on how emacs can pass a flag into the repl would be super helpful.

    1. Hey Craig! Glad this helped, and thanks for catching the Typo!

      To pass flags to the Emacs Erlang shell define the following in your .emacs:

      (defun erl-shell (flags)
      "Start an erlang shell with flags"
      (interactive (list (read-string "Flags: ")))
      (set 'inferior-erlang-machine-options (split-string flags))

      Then to start the shell you do this will then prompt you for the flags.

      More info can be found here

    2. Then to start the shell you do "M-x erl-shell" this will then prompt you for the flags.

      Sorry for the double reply. Forgot to put the command in.

    3. Thanks for the additional information. That has saved me hours of frustration and searching around. In order to use Erlang more I need to be able to tap into legacy data we have and this has been a great help in that area.

  2. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates. paypal login