Skip to content

Commit 799dca0

Browse files
authored
Update READMEs for NpgsqlDataSource
1 parent 99e7324 commit 799dca0

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ For the full documentation, please visit [the Npgsql website](https://www.npgsql
1717
Here's a basic code snippet to get you started:
1818

1919
```csharp
20+
using Npgsql;
21+
2022
var connString = "Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase";
2123

22-
await using var conn = new NpgsqlConnection(connString);
23-
await conn.OpenAsync();
24+
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connString);
25+
var dataSource = dataSourceBuilder.Build();
26+
27+
var conn = await dataSource.OpenConnectionAsync();
2428

2529
// Insert some data
2630
await using (var cmd = new NpgsqlCommand("INSERT INTO data (some_field) VALUES (@p)", conn))

src/Npgsql.NetTopologySuite/README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ Npgsql is the open source .NET data provider for PostgreSQL. It allows you to co
22

33
This package is an Npgsql plugin which allows you to interact with spatial data provided by the PostgreSQL [PostGIS extension](https://postgis.net); PostGIS is a mature, standard extension considered to provide top-of-the-line database spatial features. On the .NET side, the plugin adds support for the types from the [NetTopologySuite library](https://github.com/NetTopologySuite/NetTopologySuite), allowing you to read and write them directly to PostgreSQL.
44

5-
To use the NetTopologySuite plugin, simply add a dependency on this package and set it up at program startup:
5+
To use the NetTopologySuite plugin, add a dependency on this package and create a NpgsqlDataSource.
66

77
```csharp
8-
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite();
9-
```
8+
using Npgsql;
9+
using NetTopologySuite.Geometries;
1010

11-
Once this is done, you can simply use NetTopologySuite types when interacting with PostgreSQL:
11+
var dataSourceBuilder = new NpgsqlDataSourceBuilder(ConnectionString);
12+
13+
dataSourceBuilder.UseNetTopologySuite();
14+
15+
var dataSource = dataSourceBuilder.Build();
16+
var conn = await dataSource.OpenConnectionAsync();
1217

13-
```csharp
1418
var point = new Point(new Coordinate(1d, 1d));
1519
conn.ExecuteNonQuery("CREATE TEMP TABLE data (geom GEOMETRY)");
1620
using (var cmd = new NpgsqlCommand("INSERT INTO data (geom) VALUES (@p)", conn))

src/Npgsql.NodaTime/README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ Npgsql is the open source .NET data provider for PostgreSQL. It allows you to co
22

33
This package is an Npgsql plugin which allows you to use the [NodaTime](https://nodatime.org) date/time library when interacting with PostgreSQL; this provides a better and safer API for dealing with date and time data.
44

5-
To use the NodaTime plugin, simply add a dependency on this package and set it up at program startup:
5+
To use the NodaTime plugin, add a dependency on this package and create a NpgsqlDataSource. Once this is done, you can use NodaTime types when interacting with PostgreSQL, just as you would use e.g. `DateTime`:
66

77
```csharp
8-
NpgsqlConnection.GlobalTypeMapper.UseNodaTime();
9-
```
8+
using Npgsql;
109

11-
Once this is done, you can simply use NodaTime types when interacting with PostgreSQL, just as you would use e.g. `DateTime`:
10+
var dataSourceBuilder = new NpgsqlDataSourceBuilder(ConnectionString);
11+
12+
dataSourceBuilder.UseNodaTime();
13+
14+
var dataSource = dataSourceBuilder.Build();
15+
var conn = await dataSource.OpenConnectionAsync();
1216

13-
```csharp
1417
// Write NodaTime Instant to PostgreSQL "timestamp with time zone" (UTC)
1518
using (var cmd = new NpgsqlCommand(@"INSERT INTO mytable (my_timestamptz) VALUES (@p)", conn))
1619
{

0 commit comments

Comments
 (0)