Skip to content
Draft
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
4 changes: 4 additions & 0 deletions docs/_assets/icon/crystal-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions docs/connect/crystal/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
(connect-crystal)=

# Crystal

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

:::{rubric} About
:::

[crystal-pg] is a native, non-blocking Postgres driver for Crystal,
building upon [crystal-db].

:::{rubric} Synopsis
:::

`shard.yml`
```yaml
name: cratedb_demo
version: 0.0.0
dependencies:
pg:
github: will/crystal-pg
```
`example.cr`
```crystal
require "db"
require "pg"

DB.open("postgres://crate:crate@localhost:5432/?sslmode=disable") do |db|

db.query "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3" do |rs|
puts "#{rs.column_name(0)} #{rs.column_name(1)}"
rs.each do
puts "#{rs.read(String)}: #{rs.read(Int32)}"
end
end

end
```

:::{include} ../_cratedb.md
:::
```shell
shards install
```
```shell
crystal example.cr
```

:::{rubric} SSL connection
:::

Use the `sslmode=require&auth_methods=cleartext` parameters,
and replace username, password,
and hostname with values matching your environment.
Also use this variant to connect to CrateDB Cloud.

```crystal
DB.open("postgres://admin:password@testcluster.cratedb.net:5432/?sslmode=require&auth_methods=cleartext")
```


[crystal-db]: https://github.com/crystal-lang/crystal-db
[crystal-pg]: https://github.com/will/crystal-pg
14 changes: 14 additions & 0 deletions docs/connect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ Any (ODBC)
C#
::::

::::{grid-item-card}
:link: connect-crystal
:link-type: ref
:link-alt: Connect to CrateDB using Crystal
:class-body: sd-fs-1 sd-text-center
:class-footer: sd-fs-5 sd-font-weight-bold
```{image} /_assets/icon/crystal-logo.svg
:height: 70px
```
+++
Crystal
::::

::::{grid-item-card}
:link: connect-elixir
:link-type: ref
Expand Down Expand Up @@ -336,6 +349,7 @@ application
:maxdepth: 1
:hidden:

crystal/index
csharp/index
elixir/index
erlang/index
Expand Down