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
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.
64 changes: 64 additions & 0 deletions docs/connect/crystal/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
(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/doc?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} CrateDB Cloud
:::

For connecting to CrateDB Cloud, use `sslmode=require&auth_methods=cleartext`
parameters, and replace username, password and hostname with values matching
your environment.
```crystal
DB.open("postgres://admin:[email protected]:5432/doc?sslmode=require&auth_methods=cleartext")
```
Comment on lines +52 to +60
Copy link
Member Author

@amotl amotl Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem

When not permitting auth_methods=cleartext, the connection will fail, because cleartext is disabled by default.

Unhandled exception:  (DB::ConnectionRefused)
Caused by: server asked for disabled authentication method: cleartext (PQ::ConnectionError)

Background

By default this driver will accept scram-sha-256 and md5, as well as
trust. However cleartext is disabled by default. You can control exactly
which auth methods the client will accept by passing in a comma separated list
to the auth_methods parameter.

-- https://github.com/will/crystal-pg/blob/c5b8ac1ac5713fc58f974d8a4327887a0b297594/README.md?plain=1#L164-L169

Thoughts

Do you think it is applicable to report this to crate/crate, so it may possibly support md5 or scram-sha-256 in the future?

/cc @matriv, @seut



[crystal-db]: https://github.com/crystal-lang/crystal-db
[crystal-pg]: https://github.com/will/crystal-pg
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} Crystal
:link: connect-crystal
:link-type: ref
:link-alt: Connect to CrateDB using Crystal
:padding: 3
:text-align: center
:class-card: sd-pt-3
:class-body: sd-fs-1
:class-title: sd-fs-6
```{image} /_assets/icon/crystal-logo.svg
:height: 70px
```
::::

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

crystal/index
java
javascript
php
Expand Down