Skip to content

Commit

Permalink
Add Asynchronous Docs (PostgreSQLCopyHelper#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
say25 authored Sep 30, 2019
1 parent c45f005 commit 8e942c3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,36 @@ var copyHelper = new PostgreSQLCopyHelper<TestEntity>("sample", "unit_test")

And then we can use it to efficiently store the data:

Synchronously:

```csharp
private ulong WriteToDatabase(PostgreSQLCopyHelper<TestEntity> copyHelper, IEnumerable<TestEntity> entities)
{
using (var connection = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=sampledb;User Id=philipp;Password=test_pwd;"))
{
connection.Open();

// Returns count of rows written
// Returns count of rows written
return copyHelper.SaveAll(connection, entities);
}
}
```

Or asynchronously:

```csharp
private async Task<ulong> WriteToDatabaseAsync(PostgreSQLCopyHelper<TestEntity> copyHelper, IEnumerable<TestEntity> entities, CancellationToken cancellationToken = default)
{
using (var connection = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=sampledb;User Id=philipp;Password=test_pwd;"))
{
await connection.OpenAsync(cancellationToken);

// Returns count of rows written
return await copyHelper.SaveAllAsync(connection, entities, cancellationToken);
}
}
```

## Case-Sensitive Identifiers ##

By default the library does not apply quotes to identifiers, such as Table Names and Column Names. If you want PostgreSQL-conform quoting for identifiers,
Expand Down

0 comments on commit 8e942c3

Please sign in to comment.