From 758b8415227fdb2107861e270e6c98526b0e3e85 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 3 Nov 2025 20:20:12 +0100 Subject: [PATCH] Connect: Add Raku --- docs/connect/index.md | 14 +++++++ docs/connect/raku/index.md | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 docs/connect/raku/index.md diff --git a/docs/connect/index.md b/docs/connect/index.md index 84404e82..3a51146f 100644 --- a/docs/connect/index.md +++ b/docs/connect/index.md @@ -207,6 +207,19 @@ Python R :::: +::::{grid-item-card} +:link: connect-raku +:link-type: ref +:class-body: sd-fs-1 sd-text-center +:class-footer: sd-fs-5 sd-font-weight-bold + +```{image} https://upload.wikimedia.org/wikipedia/commons/8/85/Camelia.svg +:width: 40px +``` ++++ +Raku +:::: + ::::{grid-item-card} :link: connect-ruby :link-type: ref @@ -349,6 +362,7 @@ kotlin/index php/index python/index r/index +raku/index ruby rust/index scala/index diff --git a/docs/connect/raku/index.md b/docs/connect/raku/index.md new file mode 100644 index 00000000..09d2b243 --- /dev/null +++ b/docs/connect/raku/index.md @@ -0,0 +1,78 @@ +(connect-raku)= + +# Raku + +:::{div} .float-right .text-right +```{image} https://upload.wikimedia.org/wikipedia/commons/8/85/Camelia.svg +:height: 60px +``` +::: +:::{div} .clearfix +::: + +:::{div} sd-text-muted +Connect to CrateDB from Raku applications. +::: + +:::{rubric} About +::: + +[Protocol::Postgres] is a sans-io PostgreSQL client for Raku. + +:::{rubric} Synopsis +::: + +`example.raku` +```raku +use v6.d; +use Protocol::Postgres; + +my $host = "localhost"; +my $port = 5432; +my $user = "crate"; +my $password = "crate"; +my $database = "crate"; + +my $socket = await IO::Socket::Async.connect($host, $port); +my $client = Protocol::Postgres::Client.new; +$socket.Supply(:bin).act({ $client.incoming-data($^data) }); +$client.outbound-data.act({ $socket.write($^data) }); + +await $client.startup($user, $database, $password); + +my $resultset = await $client.query('SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3', []); +react { + whenever $resultset.hash-rows -> (:$mountain, :$height) { + say "$mountain: $height"; + } +} +``` + +:::{rubric} Example +::: + +Create the file `example.raku` including the synopsis code shared above. + +:::{include} ../_cratedb.md +::: +```shell +zef install Protocol::Postgres +raku example.raku +``` + +:::{rubric} CrateDB Cloud +::: + +For connecting to CrateDB Cloud, replace username, password, and +hostname with values matching your environment. + +```raku +my $host = "testcluster.cratedb.net"; +my $port = 5432; +my $user = "admin"; +my $password = "password"; +my $database = "crate"; +``` + + +[Protocol::Postgres]: https://raku.land/zef:leont/Protocol::Postgres