-
Notifications
You must be signed in to change notification settings - Fork 2
Driver: Add page about Erlang #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b34793a
859fa3a
3e30d05
a49df3d
b3a5468
6398449
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
| ```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 | ||
| 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 | ||
| ::: | ||
amotl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I wasn't clear, I meant about the header
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I am confused? The commit replaces the header
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fixed in the epgsql file but not here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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