There seem to be a ton of options for playing around with Erlang and I am just lost as which option is best for certain situations.
In particular I want to play around with some Erlang database drivers. But I obviously need to load these dependencies.
Rebar3 seems like a good place to start., but what type of project should I create (what project do you create)?
And then how to actually run and play around? Use the shell? An escript? An application?
Rebar3 shell seems ideal as I think rebar3 will allow changes/recompile/rerun within it.
Thanks for any help.
5 Likes
seriyps
November 26, 2021, 5:37pm
2
I personally would create an “OTP application” with rebar3:
$ rebar3 new app name=my_database
$ cd my_database
$ nano rebar.config
$ cat rebar.config
{erl_opts, [debug_info]}.
{deps, [
epgsql, % postgresql driver
mysql % mysql-otp library
]}.
{shell, [
% {config, "config/sys.config"},
{apps, [my_database]}
]}.
$ rebar3 upgrade
$ rebar3 shell
> {ok, C} = epgsql:connect(#{
host => "localhost",
username => "username",
password => "psss",
database => "test_db",
timeout => 4000
}).
> epgsql:squery(C, "SELECT 1").
7 Likes
Thanks Sergey!
Interesting. So, I am not seeing an immediate big difference between rebar3 new app
and rebar3 new escript
(at least for just playing around with a library or 2).
$ rebar3 new escript sandbox
$ rebar3 shell
> {ok, Db} = pgsql:connect("localhost", "postgres", "postgres", "postgres", 5432).
> pgsql:pquery(Db, "select 1 where 1 = $1" ,[1])
using dep {deps, [{p1_pgsql, {git, "https://github.com/processone/p1_pgsql.git", {tag, "1.1.12"}}}]}.
But thanks again - this is giving me more confidence now
3 Likes
seriyps
November 27, 2021, 2:16pm
4
You normally use escript
if you want to create a command-line utility and app
in every other case.
May I ask (as I am one of the maintainers of epgsql
) why you prefer p1_pgsql
over epgsql
?
3 Likes
Not my choice
We will likely move off of it soon-ish. We have other erlang apps that do use epgsql
and will probably move to that across the board.
4 Likes
FWIW I recommend pgo . I like the design.
3 Likes