Skip to content

Commit bde904d

Browse files
committed
Connect: Add C#, F#, Visual Basic
1 parent c2721f4 commit bde904d

File tree

8 files changed

+422
-0
lines changed

8 files changed

+422
-0
lines changed

docs/_assets/icon/csharp-logo.svg

Lines changed: 10 additions & 0 deletions
Loading

docs/_assets/icon/fsharp-logo.svg

Lines changed: 59 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

docs/_include/links.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
[ADBC]: https://arrow.apache.org/docs/format/ADBC.html
55
[Admin UI]: inv:crate-admin-ui:*:label#index
6+
[ADO.NET Overview]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-overview
67
[Amazon DynamoDB Streams]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html
78
[Amazon Kinesis Data Streams]: https://docs.aws.amazon.com/streams/latest/dev/introduction.html
89
[Apache Airflow]: https://airflow.apache.org/
@@ -13,6 +14,7 @@
1314
[BM25]: https://en.wikipedia.org/wiki/Okapi_BM25
1415
[cloud-datashader-colab]: https://colab.research.google.com/github/crate/cratedb-examples/blob/amo/cloud-datashader/topic/timeseries/explore/cloud-datashader.ipynb
1516
[cloud-datashader-github]: https://github.com/crate/cratedb-examples/blob/amo/cloud-datashader/topic/timeseries/explore/cloud-datashader.ipynb
17+
[Connection Strings in ADO.NET]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-strings
1618
[CTE]: inv:crate-reference#sql_dql_with
1719
[CrateDB BLOBs]: inv:crate-reference:*:label#blob_support
1820
[CrateDB Cloud]: inv:cloud:*:label#index

docs/connect/csharp/index.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
:::{include} /_include/links.md
2+
:::
3+
4+
(connect-csharp)=
5+
# C#
6+
7+
:::{div} sd-text-muted
8+
Connect to CrateDB from C# .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+
17+
:::{rubric} Synopsis
18+
:::
19+
20+
`example.csproj`
21+
```xml
22+
<Project Sdk="Microsoft.NET.Sdk">
23+
24+
<PropertyGroup>
25+
<OutputType>Exe</OutputType>
26+
<TargetFramework>net$(NETCoreAppMaximumVersion)</TargetFramework>
27+
<GenerateProgramFile>false</GenerateProgramFile>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<PackageReference Include="Npgsql" Version="10.0.0-rc.1" />
32+
</ItemGroup>
33+
34+
</Project>
35+
```
36+
`example.cs`
37+
```c#
38+
using Npgsql;
39+
using System;
40+
41+
// Connect to database.
42+
var connString = "Host=localhost;Port=5432;Username=crate;Password=crate;Database=doc;Sslmode=disable";
43+
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connString);
44+
var dataSource = dataSourceBuilder.Build();
45+
var conn = dataSource.OpenConnection();
46+
47+
// Invoke basic query.
48+
var cmd = new NpgsqlCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3", conn);
49+
50+
// Display results.
51+
var reader = cmd.ExecuteReader();
52+
while (reader.Read())
53+
Console.WriteLine($"{reader.GetString(0)}: {reader.GetInt32(1)}");
54+
```
55+
56+
:::{include} ../_cratedb.md
57+
:::
58+
```shell
59+
export DOTNET_CLI_TELEMETRY_OPTOUT=true
60+
dotnet run
61+
```
62+
63+
:::{rubric} CrateDB Cloud
64+
:::
65+
66+
For connecting to CrateDB Cloud, use `Sslmode=require`, and
67+
replace hostname, username, and password with values matching
68+
your environment.
69+
```c#
70+
var connString = "Host=testcluster.cratedb.net;Port=5432;Username=admin;Password=password;Database=doc;Sslmode=require";
71+
```
72+
73+
## Examples
74+
75+
:::{card}
76+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/csharp-npgsql
77+
:link-type: url
78+
{material-outlined}`play_arrow;2em`
79+
Connect to CrateDB and CrateDB Cloud using .NET (C#)
80+
+++
81+
Demonstrates a basic example using Npgsql with CrateDB.
82+
:::
83+
84+
:::{card}
85+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/csharp-efcore
86+
:link-type: url
87+
{material-outlined}`play_arrow;2em`
88+
Connect to CrateDB and CrateDB Cloud using the Npgsql Entity Framework
89+
+++
90+
Demonstrates the Npgsql Entity Framework Core provider for PostgreSQL with CrateDB.
91+
:::
92+
93+
[![C# Npgsql](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-npgsql.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-npgsql.yml)
94+
[![C# EF Core](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-efcore.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-efcore.yml)
95+
96+
## See also
97+
98+
:::{div}
99+
- [Connection Strings in ADO.NET]
100+
- [ADO.NET Overview]
101+
:::
102+
103+
104+
[Npgsql]: https://www.npgsql.org/

docs/connect/fsharp/index.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
:::{include} ../_cratedb.md
79+
:::
80+
```shell
81+
export DOTNET_CLI_TELEMETRY_OPTOUT=true
82+
dotnet run
83+
```
84+
85+
:::{rubric} CrateDB Cloud
86+
:::
87+
88+
For connecting to CrateDB Cloud, use `Sslmode=require`, and
89+
replace hostname, username, and password with values matching
90+
your environment.
91+
```f#
92+
let connString = "postgres://admin:[email protected]:5432/doc?sslmode=require";
93+
```
94+
95+
## See also
96+
97+
:::{div}
98+
- [Connection Strings in ADO.NET]
99+
- [ADO.NET Overview]
100+
:::
101+
102+
103+
[Npgsql]: https://www.npgsql.org/
104+
[Npgsql.FSharp]: https://github.com/Zaid-Ajaj/Npgsql.FSharp

docs/connect/index.md

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

52+
::::{grid-item-card} C#
53+
:link: connect-csharp
54+
:link-type: ref
55+
:link-alt: Connect to CrateDB using C#
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/csharp-logo.svg
62+
:height: 50px
63+
```
64+
::::
65+
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+
5280
::::{grid-item-card} Java
5381
:link: connect-java
5482
:link-type: ref
@@ -113,6 +141,20 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
113141

114142
::::
115143

144+
::::{grid-item-card} Visual Basic
145+
:link: connect-visualbasic
146+
:link-type: ref
147+
:link-alt: Connect to CrateDB using Visual Basic
148+
:padding: 3
149+
:text-align: center
150+
:class-card: sd-pt-3
151+
:class-body: sd-fs-1
152+
:class-title: sd-fs-6
153+
```{image} /_assets/icon/visualbasic-logo.svg
154+
:height: 50px
155+
```
156+
::::
157+
116158
:::::
117159

118160

@@ -182,11 +224,14 @@ application
182224
:maxdepth: 1
183225
:hidden:
184226
227+
csharp/index
228+
fsharp/index
185229
java
186230
javascript
187231
php
188232
python
189233
ruby
234+
visualbasic/index
190235
natural
191236
All drivers <drivers>
192237
```

0 commit comments

Comments
 (0)