Skip to content
Open
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
92 changes: 92 additions & 0 deletions docs/connect/elixir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
(connect-elixir)=

# Elixir

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

:::{rubric} About
:::

[Postgrex] is the canonical PostgreSQL driver for Elixir.

:::{rubric} Synopsis
:::

`mix.exs`
```elixir
defmodule CrateDbExample do
use Mix.Project
def project do
[
app: :cratedb_elixir_example,
version: "0.0.0",
deps: [{:postgrex, "~> 0.21.0"}],
]
end
end
```
`example.exs`
```elixir
options = [
hostname: "localhost",
port: 5432,
ssl: false,
username: "crate",
password: "crate",
database: "doc",
backoff_type: :stop,
max_restarts: 0,
show_sensitive_data_on_connection_error: true,
]

{:ok, conn} = Postgrex.start_link(options)
result = Postgrex.query!(conn, "SELECT region, mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5", [])
IO.inspect(result)
```

Start CrateDB using Docker or Podman, then compile and invoke the example program.
```shell
docker run --rm --publish=5432:5432 crate -Cdiscovery.type=single-node
```
```shell
mix deps.get
mix run example.exs
```

:::{rubric} CrateDB Cloud
:::

For connecting to CrateDB Cloud, adjust the `ssl: true` parameter,
and replace hostname, username, and password with values matching your
environment.
```elixir
options = [
hostname: "testcluster.cratedb.net",
port: 5432,
ssl: true,
username: "admin",
password: "password",
database: "doc",
backoff_type: :stop,
max_restarts: 0,
show_sensitive_data_on_connection_error: true,
]
```

## Example

:::{card}
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/elixir-postgrex
:link-type: url
{material-outlined}`play_arrow;2em`
Connect to CrateDB and CrateDB Cloud using Elixir.
+++
Demonstrates a basic example that uses the Postgrex driver.
:::

[![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)


[Postgrex]: https://hexdocs.pm/postgrex/readme.html
15 changes: 15 additions & 0 deletions docs/connect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
:margin: 4 4 0 0
:padding: 0

::::{grid-item-card} Elixir
:link: connect-elixir
:link-type: ref
:link-alt: Connect to CrateDB using Elixir
:padding: 3
:text-align: center
:class-card: sd-pt-3
:class-body: sd-fs-1
:class-title: sd-fs-6
```{image} https://cdn.prod.website-files.com/6047a9e35e5dc54ac86ddd90/63064ea203056632171dfaa2_43c017db.png
:width: 40px
```
::::

::::{grid-item-card} Java
:link: connect-java
:link-type: ref
Expand Down Expand Up @@ -182,6 +196,7 @@ application
:maxdepth: 1
:hidden:

elixir
java
javascript
php
Expand Down