Skip to content

Commit 374aa50

Browse files
committed
Connect/Erlang: Each item on a separate page
1 parent 11550a8 commit 374aa50

File tree

3 files changed

+147
-125
lines changed

3 files changed

+147
-125
lines changed

docs/connect/erlang/epgsql.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
(erlang-epgsql)=
2+
3+
# Erlang epgsql
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from Erlang using epgsql.
7+
:::
8+
9+
:::{rubric} About
10+
:::
11+
12+
[epgsql] is the designated Erlang PostgreSQL client library.
13+
14+
:::{rubric} Synopsis
15+
:::
16+
17+
`rebar.config`
18+
```erlang
19+
{deps,
20+
[
21+
{epgsql, ".*", {git, "https://github.com/epgsql/epgsql.git", {tag, "4.8.0"}}}
22+
]}.
23+
```
24+
`epgsql_example.erl`
25+
```erlang
26+
-module(epgsql_example).
27+
-export([start/0]).
28+
29+
start() ->
30+
{ok, C} = epgsql:connect(#{
31+
host => "localhost",
32+
username => "crate",
33+
password => "crate",
34+
database => "doc",
35+
port => 5432,
36+
timeout => 4000
37+
}),
38+
{ok, _, Result} = epgsql:squery(C, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3"),
39+
io:fwrite("~p~n", [Result]),
40+
ok = epgsql:close(C),
41+
init:stop().
42+
```
43+
44+
:::{include} ../_cratedb.md
45+
:::
46+
```shell
47+
rebar3 compile
48+
erlc epgsql_example.erl
49+
rebar3 shell --eval 'epgsql_example:start().'
50+
```
51+
52+
:::{rubric} CrateDB Cloud
53+
:::
54+
55+
For connecting to CrateDB Cloud, start the Erlang [SSL application] first,
56+
use the `ssl` and `ssl_opts` arguments on `epgsql:connect`, and
57+
replace username, password, and hostname with values matching
58+
your environment.
59+
```erlang
60+
start() ->
61+
ssl:start(),
62+
{ok, C} = epgsql:connect(#{
63+
host => "testcluster.cratedb.net",
64+
username => "admin",
65+
password => "password",
66+
database => "doc",
67+
port => 5432,
68+
ssl => true,
69+
ssl_opts => [{verify, verify_none}],
70+
timeout => 4000
71+
}),
72+
```
73+
74+
75+
[epgsql]: https://github.com/epgsql/epgsql
76+
[SSL application]: https://www.erlang.org/docs/28/apps/ssl/ssl_app.html

docs/connect/erlang/index.md

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -6,129 +6,7 @@
66
Connect to CrateDB from Erlang applications.
77
:::
88

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-
::::{todo}
19-
Enable this include with the [ODBC patch](https://github.com/crate/cratedb-guide/pull/411).
20-
```md
21-
:::{include} _odbc-setup-widget.md
22-
:::
23-
```
24-
::::
25-
26-
:::{rubric} Synopsis
27-
:::
28-
29-
Before running the example, ensure the PostgreSQL ODBC driver is
30-
installed on your system.
31-
32-
`odbc_example.erl`
33-
```erlang
34-
-module(odbc_example).
35-
36-
main(_) ->
37-
odbc:start(),
38-
{ok, Ref} = odbc:connect("Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []),
39-
io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]),
40-
init:stop().
41-
```
42-
43-
:::{include} ../_cratedb.md
44-
:::
45-
```shell
46-
escript odbc_example.erl
47-
```
48-
49-
:::{rubric} CrateDB Cloud
50-
:::
51-
52-
For connecting to CrateDB Cloud, start the Erlang [SSL application],
53-
add `sslmode=require`, and replace `Server`, `Uid`, and `Pwd` with
54-
values matching your environment.
55-
56-
`odbc_example.erl`
57-
```erlang
58-
-module(odbc_example).
59-
60-
main(_) ->
61-
ssl:start(),
62-
odbc:start(),
63-
{ok, Ref} = odbc:connect("Driver={PostgreSQL};Server=testcluster.cratedb.net;Port=5432;sslmode=require;Uid=admin;Pwd=password", []),
64-
io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]),
65-
init:stop().
66-
```
67-
68-
69-
## epgsql
70-
71-
[epgsql] is the designated Erlang PostgreSQL client library.
72-
73-
`rebar.config`
74-
```erlang
75-
{deps,
76-
[
77-
{epgsql, ".*", {git, "https://github.com/epgsql/epgsql.git", {tag, "4.8.0"}}}
78-
]}.
79-
```
80-
`epgsql_example.erl`
81-
```erlang
82-
-module(epgsql_example).
83-
-export([start/0]).
84-
85-
start() ->
86-
{ok, C} = epgsql:connect(#{
87-
host => "localhost",
88-
username => "crate",
89-
password => "crate",
90-
database => "doc",
91-
port => 5432,
92-
timeout => 4000
93-
}),
94-
{ok, _, Result} = epgsql:squery(C, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3"),
95-
io:fwrite("~p~n", [Result]),
96-
ok = epgsql:close(C),
97-
init:stop().
98-
```
99-
100-
:::{include} ../_cratedb.md
101-
:::
102-
```shell
103-
rebar3 compile
104-
erlc epgsql_example.erl
105-
rebar3 shell --eval 'epgsql_example:start().'
106-
```
107-
108-
:::{rubric} CrateDB Cloud
9+
:::{toctree}
10+
odbc
11+
epgsql
10912
:::
110-
111-
For connecting to CrateDB Cloud, start the Erlang [SSL application] first,
112-
use the `ssl` and `ssl_opts` arguments on `epgsql:connect`, and
113-
replace username, password, and hostname with values matching
114-
your environment.
115-
```erlang
116-
start() ->
117-
ssl:start(),
118-
{ok, C} = epgsql:connect(#{
119-
host => "testcluster.cratedb.net",
120-
username => "admin",
121-
password => "password",
122-
database => "doc",
123-
port => 5432,
124-
ssl => true,
125-
ssl_opts => [{verify, verify_none}],
126-
timeout => 4000
127-
}),
128-
```
129-
130-
131-
[epgsql]: https://github.com/epgsql/epgsql
132-
[Erlang ODBC examples]: https://www.erlang.org/doc/apps/odbc/getting_started.html
133-
[ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html
134-
[SSL application]: https://www.erlang.org/docs/28/apps/ssl/ssl_app.html

docs/connect/erlang/odbc.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
(erlang-odbc)=
2+
3+
# Erlang ODBC
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from Erlang using ODBC.
7+
:::
8+
9+
:::{rubric} About
10+
:::
11+
12+
Erlang includes an [ODBC application] out of the box that provides an
13+
interface to communicate with relational SQL-databases, see also
14+
[Erlang ODBC examples].
15+
16+
::::{todo}
17+
Enable this include with the [ODBC patch](https://github.com/crate/cratedb-guide/pull/411).
18+
```md
19+
:::{include} _odbc-setup-widget.md
20+
:::
21+
```
22+
::::
23+
24+
:::{rubric} Synopsis
25+
:::
26+
27+
Before running the example, ensure the PostgreSQL ODBC driver is
28+
installed on your system.
29+
30+
`odbc_example.erl`
31+
```erlang
32+
-module(odbc_example).
33+
34+
main(_) ->
35+
odbc:start(),
36+
{ok, Ref} = odbc:connect("Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []),
37+
io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]),
38+
init:stop().
39+
```
40+
41+
:::{include} ../_cratedb.md
42+
:::
43+
```shell
44+
escript odbc_example.erl
45+
```
46+
47+
:::{rubric} CrateDB Cloud
48+
:::
49+
50+
For connecting to CrateDB Cloud, start the Erlang [SSL application],
51+
add `sslmode=require`, and replace `Server`, `Uid`, and `Pwd` with
52+
values matching your environment.
53+
54+
`odbc_example.erl`
55+
```erlang
56+
-module(odbc_example).
57+
58+
main(_) ->
59+
ssl:start(),
60+
odbc:start(),
61+
{ok, Ref} = odbc:connect("Driver={PostgreSQL};Server=testcluster.cratedb.net;Port=5432;sslmode=require;Uid=admin;Pwd=password", []),
62+
io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]),
63+
init:stop().
64+
```
65+
66+
67+
[Erlang ODBC examples]: https://www.erlang.org/doc/apps/odbc/getting_started.html
68+
[ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html

0 commit comments

Comments
 (0)