Skip to content

Commit 88f78ba

Browse files
committed
Connect: Add Elixir
1 parent 74d74f5 commit 88f78ba

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

docs/connect/elixir/index.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
(connect-elixir)=
2+
3+
# Elixir
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from Elixir applications.
7+
:::
8+
9+
:::{rubric} About
10+
:::
11+
12+
[Postgrex] is the canonical PostgreSQL driver for Elixir.
13+
14+
:::{rubric} Synopsis
15+
:::
16+
17+
`mix.exs`
18+
```elixir
19+
defmodule CrateDbExample do
20+
use Mix.Project
21+
def project do
22+
[
23+
app: :cratedb_elixir_example,
24+
version: "0.0.0",
25+
deps: [{:postgrex, "~> 0.21.0"}],
26+
]
27+
end
28+
end
29+
```
30+
`example.exs`
31+
```elixir
32+
options = [
33+
hostname: "localhost",
34+
port: 5432,
35+
ssl: false,
36+
username: "crate",
37+
password: "crate",
38+
database: "doc",
39+
backoff_type: :stop,
40+
max_restarts: 0,
41+
show_sensitive_data_on_connection_error: true,
42+
]
43+
44+
{:ok, conn} = Postgrex.start_link(options)
45+
result = Postgrex.query!(conn, "SELECT region, mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5", [])
46+
IO.inspect(result)
47+
```
48+
49+
:::{include} ../_cratedb.md
50+
:::
51+
```shell
52+
mix deps.get
53+
mix run example.exs
54+
```
55+
56+
:::{rubric} CrateDB Cloud
57+
:::
58+
59+
For connecting to CrateDB Cloud, adjust the `ssl: true` parameter,
60+
and replace hostname, username, and password with values matching your
61+
environment.
62+
```elixir
63+
options = [
64+
hostname: "testcluster.cratedb.net",
65+
port: 5432,
66+
ssl: true,
67+
username: "admin",
68+
password: "password",
69+
database: "doc",
70+
backoff_type: :stop,
71+
max_restarts: 0,
72+
show_sensitive_data_on_connection_error: true,
73+
]
74+
```
75+
76+
## Example
77+
78+
:::{card}
79+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/elixir-postgrex
80+
:link-type: url
81+
{material-outlined}`play_arrow;2em`
82+
Connect to CrateDB and CrateDB Cloud using Elixir.
83+
+++
84+
Demonstrates a basic example that uses the Postgrex driver.
85+
:::
86+
87+
[![Elixir Postgrex](https://github.com/crate/cratedb-examples/actions/workflows/lang-elixir-postgrex.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-elixir-postgrex.yml)
88+
89+
90+
[Postgrex]: https://hexdocs.pm/postgrex/readme.html

docs/connect/index.md

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

52+
::::{grid-item-card} Elixir
53+
:link: connect-elixir
54+
:link-type: ref
55+
:link-alt: Connect to CrateDB using Elixir
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+
```{image} https://cdn.prod.website-files.com/6047a9e35e5dc54ac86ddd90/63064ea203056632171dfaa2_43c017db.png
62+
:width: 40px
63+
```
64+
::::
65+
5266
::::{grid-item-card} Java
5367
:link: connect-java
5468
:link-type: ref
@@ -176,6 +190,7 @@ application
176190
:maxdepth: 1
177191
:hidden:
178192
193+
elixir/index
179194
java
180195
javascript
181196
php

0 commit comments

Comments
 (0)