Skip to content

Commit c6a0cd7

Browse files
committed
Connect: Add Crystal
1 parent cb0257b commit c6a0cd7

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

docs/_assets/icon/crystal-logo.svg

Lines changed: 4 additions & 0 deletions
Loading

docs/connect/crystal/index.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
(connect-crystal)=
2+
3+
# Crystal
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from Crystal applications.
7+
:::
8+
9+
:::{rubric} About
10+
:::
11+
12+
[crystal-pg] is a native, non-blocking Postgres driver for Crystal,
13+
building upon [crystal-db].
14+
15+
:::{rubric} Synopsis
16+
:::
17+
18+
`shard.yml`
19+
```yaml
20+
name: cratedb_demo
21+
version: 0.0.0
22+
dependencies:
23+
pg:
24+
github: will/crystal-pg
25+
```
26+
`example.cr`
27+
```crystal
28+
require "db"
29+
require "pg"
30+
31+
DB.open("postgres://crate:crate@localhost:5432/?sslmode=disable") do |db|
32+
33+
db.query "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3" do |rs|
34+
puts "#{rs.column_name(0)} #{rs.column_name(1)}"
35+
rs.each do
36+
puts "#{rs.read(String)}: #{rs.read(Int32)}"
37+
end
38+
end
39+
40+
end
41+
```
42+
43+
:::{include} ../_cratedb.md
44+
:::
45+
```shell
46+
shards install
47+
```
48+
```shell
49+
crystal example.cr
50+
```
51+
52+
:::{rubric} SSL connection
53+
:::
54+
55+
Use the `sslmode=require&auth_methods=cleartext` parameters,
56+
and replace username, password,
57+
and hostname with values matching your environment.
58+
Also use this variant to connect to CrateDB Cloud.
59+
60+
```crystal
61+
DB.open("postgres://admin:password@testcluster.cratedb.net:5432/?sslmode=require&auth_methods=cleartext")
62+
```
63+
64+
65+
[crystal-db]: https://github.com/crystal-lang/crystal-db
66+
[crystal-pg]: https://github.com/will/crystal-pg

docs/connect/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ Any (ODBC)
7575
C#
7676
::::
7777

78+
::::{grid-item-card}
79+
:link: connect-crystal
80+
:link-type: ref
81+
:link-alt: Connect to CrateDB using Crystal
82+
:class-body: sd-fs-1 sd-text-center
83+
:class-footer: sd-fs-5 sd-font-weight-bold
84+
```{image} /_assets/icon/crystal-logo.svg
85+
:height: 70px
86+
```
87+
+++
88+
Crystal
89+
::::
90+
7891
::::{grid-item-card}
7992
:link: connect-elixir
8093
:link-type: ref
@@ -336,6 +349,7 @@ application
336349
:maxdepth: 1
337350
:hidden:
338351
352+
crystal/index
339353
csharp/index
340354
elixir/index
341355
erlang/index

0 commit comments

Comments
 (0)