Skip to content

Commit 31cea7b

Browse files
committed
Driver/F#: Add dedicated page
1 parent 4f2c8e9 commit 31cea7b

File tree

3 files changed

+180
-0
lines changed

3 files changed

+180
-0
lines changed

docs/_assets/icon/fsharp-logo.svg

Lines changed: 59 additions & 0 deletions
Loading

docs/connect/fsharp.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
:::{include} /_include/links.md
2+
:::
3+
4+
(connect-fsharp)=
5+
# F#
6+
7+
:::{div} sd-text-muted
8+
Connect to CrateDB from F# .NET applications.
9+
:::
10+
11+
:::{rubric} About
12+
:::
13+
14+
[Npgsql] is an open source ADO\.NET Data Provider for PostgreSQL, for programs
15+
written in C#, F#, or Visual Basic.
16+
[Npgsql.FSharp] is a thin F#-friendly layer around it.
17+
18+
:::{rubric} Synopsis
19+
:::
20+
21+
`example.fsproj`
22+
```xml
23+
<Project Sdk="Microsoft.NET.Sdk">
24+
25+
<PropertyGroup>
26+
<OutputType>Exe</OutputType>
27+
<TargetFramework>net$(NETCoreAppMaximumVersion)</TargetFramework>
28+
<GenerateProgramFile>false</GenerateProgramFile>
29+
</PropertyGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Include="Npgsql" Version="10.0.0-rc.1" />
33+
<PackageReference Include="Npgsql.FSharp" Version="8.0.0" />
34+
</ItemGroup>
35+
36+
<ItemGroup>
37+
<Compile Include="example.fs" />
38+
</ItemGroup>
39+
40+
</Project>
41+
```
42+
`example.fs`
43+
```f#
44+
open Npgsql.FSharp
45+
open System
46+
47+
let connString = "postgres://crate:crate@localhost:5432/doc?sslmode=disable";
48+
49+
type Record = {
50+
mountain: string
51+
height: int
52+
}
53+
54+
[<EntryPoint>]
55+
let main args =
56+
let results = ResizeArray()
57+
58+
// Connect to database.
59+
connString
60+
|> Sql.connect
61+
62+
// Invoke basic query.
63+
|> Sql.query "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3"
64+
|> Sql.execute (fun read ->
65+
{
66+
mountain = read.text "mountain"
67+
height = read.int "height"
68+
})
69+
|> results.Add
70+
71+
// Display results.
72+
printfn "%A" results
73+
74+
// Exit program successfully.
75+
0
76+
```
77+
78+
Start CrateDB using Docker or Podman, then invoke the example program.
79+
```shell
80+
docker run --rm --publish=5432:5432 crate '-Cdiscovery.type=single-node'
81+
```
82+
```shell
83+
export DOTNET_CLI_TELEMETRY_OPTOUT=true
84+
dotnet run
85+
```
86+
87+
:::{rubric} CrateDB Cloud
88+
:::
89+
90+
For connecting to CrateDB Cloud, use `Sslmode=require`, and
91+
replace hostname, username, and password with values matching
92+
your environment.
93+
```c#
94+
let connString = "postgres://admin:password@testcluster.cratedb.net:5432/doc?sslmode=require";
95+
```
96+
97+
## See also
98+
99+
:::{div}
100+
- [Connection Strings in ADO.NET]
101+
- [ADO.NET Overview]
102+
:::
103+
104+
105+
[Npgsql]: https://www.npgsql.org/
106+
[Npgsql.FSharp]: https://github.com/Zaid-Ajaj/Npgsql.FSharp

docs/connect/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
6363
```
6464
::::
6565

66+
::::{grid-item-card} F#
67+
:link: connect-fsharp
68+
:link-type: ref
69+
:link-alt: Connect to CrateDB using F#
70+
:padding: 3
71+
:text-align: center
72+
:class-card: sd-pt-3
73+
:class-body: sd-fs-1
74+
:class-title: sd-fs-6
75+
```{image} /_assets/icon/fsharp-logo.svg
76+
:height: 50px
77+
```
78+
::::
79+
6680
::::{grid-item-card} Java
6781
:link: connect-java
6882
:link-type: ref
@@ -197,6 +211,7 @@ application
197211
:hidden:
198212
199213
csharp
214+
fsharp
200215
java
201216
javascript
202217
php

0 commit comments

Comments
 (0)