Skip to content

Commit 304f3b1

Browse files
committed
Driver/Erlang: Add dedicated page
1 parent 1d3251e commit 304f3b1

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

docs/connect/erlang.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
(connect-erlang)=
2+
3+
# Erlang
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from Erlang applications.
7+
:::
8+
9+
## ODBC
10+
11+
:::{rubric} About
12+
:::
13+
14+
Erlang includes an [ODBC application] out of the box that provides an
15+
interface to communicate with relational SQL-databases, see also
16+
[Erlang ODBC examples].
17+
18+
:::{rubric} Synopsis
19+
:::
20+
21+
`odbcinst.ini`
22+
```ini
23+
[PostgreSQL]
24+
Description = PostgreSQL ODBC driver
25+
Driver = /usr/local/lib/psqlodbcw.so
26+
```
27+
```shell
28+
odbcinst -i -d -f odbcinst.ini
29+
```
30+
`odbc_demo.erl`
31+
```erlang
32+
-module(odbc_demo).
33+
-export([start/0]).
34+
35+
start() ->
36+
odbc:start(),
37+
{ok, Ref} = odbc:connect("Driver={PostgreSQL};Servername=localhost;Portnumber=5432;Uid=crate;Pwd=crate", []),
38+
io:fwrite("~p", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]).
39+
```
40+
```shell
41+
erlc odbc_demo.erl && erl -s odbc_demo
42+
```
43+
44+
## epgsql
45+
46+
[epgsql] is the designated Erlang PostgreSQL client library.
47+
48+
`rebar.config`
49+
```erlang
50+
{deps,
51+
[
52+
{epgsql, ".*", {git, "https://github.com/epgsql/epgsql.git", {tag, "4.8.0"}}}
53+
]}.
54+
```
55+
```shell
56+
rebar3 compile
57+
```
58+
`epgsql_demo.erl`
59+
```erlang
60+
-module(epgsql_demo).
61+
-export([start/0]).
62+
63+
start() ->
64+
{ok, C} = epgsql:connect(#{
65+
host => "localhost",
66+
username => "crate",
67+
password => "crate",
68+
database => "doc",
69+
port => 5432,
70+
timeout => 4000
71+
}),
72+
{ok, _, Result} = epgsql:squery(C, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3"),
73+
io:fwrite("~p", [Result]),
74+
ok = epgsql:close(C).
75+
```
76+
```shell
77+
erlc epgsql_demo.erl
78+
erl -pa ebin ./_build/default/lib/epgsql/ebin ./_build/default/lib/epgsql/include -s epgsql_demo
79+
```
80+
81+
82+
[epgsql]: https://github.com/epgsql/epgsql
83+
[Erlang ODBC examples]: https://www.erlang.org/doc/apps/odbc/getting_started.html
84+
[ODBC application]: https://www.erlang.org/doc/apps/odbc/odbc.html

docs/connect/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
4949
:margin: 4 4 0 0
5050
:padding: 0
5151

52+
::::{grid-item-card} Erlang
53+
:link: connect-erlang
54+
:link-type: ref
55+
:link-alt: Connect to CrateDB using Erlang
56+
:padding: 3
57+
:text-align: center
58+
:class-card: sd-pt-3
59+
:class-body: sd-fs-1
60+
:class-title: sd-fs-6
61+
{fab}`erlang`
62+
::::
63+
5264
::::{grid-item-card} Java
5365
:link: connect-java
5466
:link-type: ref
@@ -182,6 +194,7 @@ application
182194
:maxdepth: 1
183195
:hidden:
184196
197+
erlang
185198
java
186199
javascript
187200
php

0 commit comments

Comments
 (0)