Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions docs/connect/erlang/epgsql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
(erlang-epgsql)=

# Erlang epgsql

:::{div} sd-text-muted
Connect to CrateDB from Erlang using epgsql.
:::

:::{rubric} About
:::

[epgsql] is the designated Erlang PostgreSQL client library.

:::{rubric} Synopsis
:::

`rebar.config`
```erlang
{deps,
[
{epgsql, ".*", {git, "https://github.com/epgsql/epgsql.git", {tag, "4.8.0"}}}
]}.
```
`epgsql_example.erl`
```erlang
-module(epgsql_example).
-export([start/0]).

start() ->
{ok, C} = epgsql:connect(#{
host => "localhost",
username => "crate",
password => "crate",
database => "doc",
port => 5432,
timeout => 4000
}),
{ok, _, Result} = epgsql:squery(C, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3"),
io:fwrite("~p~n", [Result]),
ok = epgsql:close(C),
init:stop().
```

:::{rubric} SSL connection
:::

Start the Erlang [SSL application] first,
use the `ssl` and `ssl_opts` arguments on `epgsql:connect`, and
replace username, password, and hostname with values matching
your environment.

Also use this variant to connect to CrateDB Cloud.
Comment on lines +44 to +52
Copy link
Member Author

@amotl amotl Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @matriv: This is the new text. It is included in the PR for me. Thanks again!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another place (odbc) which also says Cloud

```erlang
start() ->
ssl:start(),
{ok, C} = epgsql:connect(#{
host => "testcluster.cratedb.net",
username => "admin",
password => "password",
database => "doc",
port => 5432,
ssl => true,
ssl_opts => [{verify, verify_none}],
timeout => 4000
}),
```

:::{rubric} Example
:::

Create the files `rebar.config` and `epgsql_example.erl` including the synopsis code shared above.

:::{include} ../_cratedb.md
:::
```shell
rebar3 compile
erlc epgsql_example.erl
rebar3 shell --eval 'epgsql_example:start().'
```


[epgsql]: https://github.com/epgsql/epgsql
[SSL application]: https://www.erlang.org/docs/28/apps/ssl/ssl_app.html
12 changes: 12 additions & 0 deletions docs/connect/erlang/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(connect-erlang)=

# Erlang

:::{div} sd-text-muted
Connect to CrateDB from Erlang applications.
:::

:::{toctree}
odbc
epgsql
:::
72 changes: 72 additions & 0 deletions docs/connect/erlang/odbc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
(erlang-odbc)=

# Erlang ODBC

:::{div} sd-text-muted
Connect to CrateDB from Erlang using ODBC.
:::

:::{rubric} About
:::

Erlang includes an [ODBC application] out of the box that provides an
interface to communicate with relational SQL-databases, see also
[Erlang ODBC examples].

:::{rubric} Install
:::

:::{include} ../odbc/install.md
:::

:::{rubric} Synopsis
:::

Before running the example, ensure the PostgreSQL ODBC driver is
installed on your system.

`odbc_example.erl`
```erlang
-module(odbc_example).

main(_) ->
odbc:start(),
{ok, Ref} = odbc:connect("Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []),
io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]),
init:stop().
```

:::{rubric} CrateDB Cloud
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the ssl example is not only relevant for the cloud, so I would change the title to SSL connection or similar and then explain that this is mandatory for cloud.

Copy link
Member Author

@amotl amotl Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an adjustment: 6398449. Let me know if you want to phrase it differently, or add a suggestion right away. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I wasn't clear, I meant about the header CreateDB Cloud.

Copy link
Member Author

@amotl amotl Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am confused? The commit replaces the header :::{rubric} CrateDB Cloud with :::{rubric} SSL connection, as you suggested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it in the commit, but not in the PR somehow, anyway I'm approving, maybe some github hiccup? you'll figure it out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fixed in the epgsql file but not here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was clearly an oversight, thanks. I've fixed it with GH-474.

NB: Somehow I memorized that Erlang/ODBC/SSL would not be possible / failed for me while exercising it the other day. Apparently, I remembered it wrongly, but that's the reason I didn't look into this file again. Thanks for your understanding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx!

:::

For connecting to CrateDB Cloud, start the Erlang [SSL application],
add `sslmode=require`, and replace `Server`, `Uid`, and `Pwd` with
values matching your environment.

`odbc_example.erl`
```erlang
-module(odbc_example).

main(_) ->
ssl:start(),
odbc:start(),
{ok, Ref} = odbc:connect("Driver={PostgreSQL Unicode};Server=testcluster.cratedb.net;Port=5432;sslmode=require;Uid=admin;Pwd=password", []),
io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]),
init:stop().
```

:::{rubric} Example
:::

Create the file `odbc_example.erl` including the synopsis code shared above.

:::{include} ../_cratedb.md
:::
```shell
escript odbc_example.erl
```


[Erlang ODBC examples]: https://www.erlang.org/doc/apps/odbc/getting_started.html
[ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html
[SSL application]: https://www.erlang.org/docs/28/apps/ssl/ssl_app.html
11 changes: 11 additions & 0 deletions docs/connect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ Any (ODBC)
Elixir
::::

::::{grid-item-card}
:link: connect-erlang
:link-type: ref
:class-body: sd-fs-1 sd-text-center
:class-footer: sd-fs-5 sd-font-weight-bold
{fab}`erlang`
+++
Erlang
::::

::::{grid-item-card}
:link: connect-go
:link-type: ref
Expand Down Expand Up @@ -229,6 +239,7 @@ application
:hidden:

elixir/index
erlang/index
go/index
java/index
javascript
Expand Down