Skip to content

Commit 60bb2b7

Browse files
committed
Driver/Dart: Add dedicated page
1 parent 1d3251e commit 60bb2b7

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

docs/_assets/icon/dart-logo.svg

Lines changed: 22 additions & 0 deletions
Loading

docs/connect/dart.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
(connect-dart)=
2+
3+
# Dart
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from Dart applications.
7+
:::
8+
9+
:::{rubric} About
10+
:::
11+
12+
[postgres] is a library for connecting to and querying PostgreSQL databases.
13+
14+
:::{rubric} Synopsis
15+
:::
16+
17+
`pubspec.yaml`
18+
```yaml
19+
name: cratedb_demo
20+
21+
dependencies:
22+
postgres: '^3.0.0'
23+
24+
environment:
25+
sdk: '^3.9.0'
26+
```
27+
28+
`example.dart`
29+
```dart
30+
library;
31+
32+
import 'package:postgres/postgres.dart';
33+
34+
void main() async {
35+
36+
final conn = await Connection.openFromUrl(
37+
'postgresql://crate:crate@localhost:5432/doc?sslmode=disable'
38+
);
39+
40+
final result = await conn.execute("SELECT mountain, region, height FROM sys.summits ORDER BY height DESC LIMIT 3");
41+
print(result);
42+
43+
await conn.close();
44+
}
45+
```
46+
47+
Start CrateDB using Docker or Podman, then compile and invoke example program.
48+
```shell
49+
docker run --rm --publish=5432:5432 crate -Cdiscovery.type=single-node
50+
```
51+
```shell
52+
dart --disable-analytics
53+
dart pub get
54+
dart example.dart
55+
```
56+
57+
:::{rubric} CrateDB Cloud
58+
:::
59+
60+
For connecting to CrateDB Cloud, use the `sslmode=require`
61+
parameter, and replace username, password, and hostname with values matching
62+
your environment.
63+
```dart
64+
final conn = await Connection.openFromUrl(
65+
'postgresql://admin:[email protected]:5432/doc?sslmode=require'
66+
);
67+
```
68+
69+
70+
[postgres]: https://pub.dev/packages/postgres

docs/connect/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
4949
:margin: 4 4 0 0
5050
:padding: 0
5151

52+
::::{grid-item-card} Dart
53+
:link: connect-dart
54+
:link-type: ref
55+
:link-alt: Connect to CrateDB using Dart
56+
:padding: 3
57+
:text-align: center
58+
:class-card: sd-pt-3
59+
:class-body: sd-fs-1
60+
:class-title: sd-fs-6
61+
```{image} /_assets/icon/dart-logo.svg
62+
:height: 50px
63+
```
64+
::::
65+
5266
::::{grid-item-card} Java
5367
:link: connect-java
5468
:link-type: ref
@@ -182,6 +196,7 @@ application
182196
:maxdepth: 1
183197
:hidden:
184198
199+
dart
185200
java
186201
javascript
187202
php

0 commit comments

Comments
 (0)