Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ jobs:
run: dotnet test --project Tests/Open.Database.Extensions.Generator.Tests -c Release -p:OdxGeneratorRoslyn=5.12 --report-xunit-trx --report-xunit-trx-filename generator-roslyn5.12.trx --results-directory TestResults/generator-roslyn5.12

# What a NuGet user gets: the packages are packed, and a project that references only them is built and run with the generator on,
# arriving through MSSqlClient alone, switched off, and with C# 12. It runs on net472 and net11.0, against LocalDB and SQLite.
# arriving through MSSqlClient alone, arriving through the Open.Database.Extensions meta-package alone, switched off, and with C# 12.
# It runs on net472 and net11.0, against LocalDB and SQLite.
- name: Run the package consumer tests
env:
ODX_REQUIRE_SQL: 1
Expand Down Expand Up @@ -220,17 +221,22 @@ jobs:
$dependencies = @($nuspec.package.metadata.dependencies.group.dependency | Where-Object id -eq 'Open.Database.Extensions.Core')
if ($dependencies.Count -eq 0) { throw "$id has no dependency on Core" }
if ($dependencies | Where-Object { $_.exclude -match 'Analyzers|Build' }) { throw "$id keeps Core's generator or build targets from its consumers" }
# The dependency is on the same version as the package, and the package carries the README and the icon (Source/Directory.Build.props).
if ($dependencies | Where-Object { $_.version -notlike "*$prefix-$suffix*" }) { throw "$id depends on a version of Core other than $prefix-$suffix" }
foreach ($entry in 'README.md', 'logo.png') {
if (-not $package.GetEntry($entry)) { throw "The $id package has no $entry" }
}
} finally { $package.Dispose() }
}
$variants = [ordered]@{ core = @(); mssqlclient = @('-p:OdxVia=MSSqlClient'); off = @('-p:OdxGenerateMaps=false'); csharp12 = @('-p:LangVersion=12') }
$variants = [ordered]@{ core = @(); mssqlclient = @('-p:OdxVia=MSSqlClient'); extensions = @('-p:OdxVia=Extensions'); off = @('-p:OdxGenerateMaps=false'); csharp12 = @('-p:LangVersion=12') }
$failed = @()
foreach ($variant in $variants.Keys) {
$options = @("-p:OdxFeed=$feed", "-p:OdxPackageVersion=$prefix-$suffix") + $variants[$variant]
$consumer = 'Tests/Open.Database.Extensions.PackageConsumer.Tests'
dotnet build $consumer -c Release --no-incremental @options
if ($LASTEXITCODE -ne 0) { $failed += "$variant (build)"; continue }
# The compiler of this SDK (global.json) supports Roslyn 5.12, so NuGet must hand it the generator in the roslyn5.12 folder, not the roslyn4.14 one.
if ($variant -in 'core', 'mssqlclient') {
if ($variant -in 'core', 'mssqlclient', 'extensions') {
$analyzers = (dotnet msbuild $consumer '-t:ResolvePackageAssets;ResolveLockFileAnalyzers' -getItem:Analyzer -p:Configuration=Release -p:TargetFramework=net11.0 @options | ConvertFrom-Json).Items.Analyzer.Identity
if (-not ($analyzers -like '*roslyn5.12*Open.Database.Extensions.Generator.dll')) { $failed += "$variant (the roslyn5.12 generator was not selected: $($analyzers -join ', '))"; continue }
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ dotnet add package Open.Database.Extensions.Core
dotnet add package Microsoft.Data.Sqlite
```

`Microsoft.Data.Sqlite` is the provider the examples use; Core works with any ADO.NET provider. `connectionString` is yours (for example `Data Source=blog.db`), and the examples use a `posts` table (`id`, `author`, `title`, `body`, `views`).
`dotnet add package Open.Database.Extensions` installs the same library (it installs Core and nothing else). `Microsoft.Data.Sqlite` is the provider the examples use; Core works with any ADO.NET provider. `connectionString` is yours (for example `Data Source=blog.db`), and the examples use a `posts` table (`id`, `author`, `title`, `body`, `views`).

| Package | What it is |
|---|---|
| `Open.Database.Extensions.Core` | The foundation, expressive commands and `Map<T>()`. Provider-agnostic: start here. |
| `Open.Database.Extensions` | Installs Core and nothing else: the same library under the shorter name. |
| `Open.Database.Extensions.Channel` | Rows into `System.Threading.Channels`. |
| `Open.Database.Extensions.Dataflow` | Rows into TPL Dataflow blocks. |
| `Open.Database.Extensions.MSSqlClient` | `SqlConnectionFactory` and SQL Server specializations on `Microsoft.Data.SqlClient`. |
Expand Down
12 changes: 12 additions & 0 deletions Source/Channel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ ChannelReader<Post> reader = connectionFactory

Brings [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) with it; install your ADO.NET provider beside it.

## The packages

| Package | What it adds | Targets |
|---|---|---|
| [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) | Expressive commands, `DbQuery` and `Map<T>()`, for any ADO.NET provider. Start here. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions](https://www.nuget.org/packages/Open.Database.Extensions/) | Installs Core and nothing else: the same library under the shorter name. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.MSSqlClient](https://www.nuget.org/packages/Open.Database.Extensions.MSSqlClient/) | `SqlConnectionFactory` and SQL Server on `Microsoft.Data.SqlClient`. | net472, net10.0, net11.0 |
| **Open.Database.Extensions.Channel** (this package) | Rows into `System.Threading.Channels`. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.Dataflow](https://www.nuget.org/packages/Open.Database.Extensions.Dataflow/) | Rows into TPL Dataflow blocks. | netstandard2.0, netstandard2.1, net10.0, net11.0 |

Each of the other packages brings Core with it. .NET 8 and .NET 9 use the netstandard2.1 build.

[Documentation](https://open-net-libraries.github.io/Open.Database.Extensions/) · [API reference](https://open-net-libraries.github.io/Open.Database.Extensions/api/index.html) · [Source and issues](https://github.com/Open-NET-Libraries/Open.Database.Extensions) · MIT license
1 change: 1 addition & 0 deletions Source/Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Already have a connection or a transaction? Pass it to `Using(...)`, or start fr
| Package | What it adds | Targets |
|---|---|---|
| **Open.Database.Extensions.Core** (this package) | Expressive commands, `DbQuery` and `Map<T>()`, for any ADO.NET provider. Start here. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions](https://www.nuget.org/packages/Open.Database.Extensions/) | Installs Core and nothing else: the same library under the shorter name. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.MSSqlClient](https://www.nuget.org/packages/Open.Database.Extensions.MSSqlClient/) | `SqlConnectionFactory` and SQL Server on `Microsoft.Data.SqlClient`. | net472, net10.0, net11.0 |
| [Open.Database.Extensions.Channel](https://www.nuget.org/packages/Open.Database.Extensions.Channel/) | Rows into `System.Threading.Channels`. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.Dataflow](https://www.nuget.org/packages/Open.Database.Extensions.Dataflow/) | Rows into TPL Dataflow blocks. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
Expand Down
12 changes: 12 additions & 0 deletions Source/Dataflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ long sent = await connectionFactory

Brings [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) with it; install your ADO.NET provider beside it.

## The packages

| Package | What it adds | Targets |
|---|---|---|
| [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) | Expressive commands, `DbQuery` and `Map<T>()`, for any ADO.NET provider. Start here. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions](https://www.nuget.org/packages/Open.Database.Extensions/) | Installs Core and nothing else: the same library under the shorter name. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.MSSqlClient](https://www.nuget.org/packages/Open.Database.Extensions.MSSqlClient/) | `SqlConnectionFactory` and SQL Server on `Microsoft.Data.SqlClient`. | net472, net10.0, net11.0 |
| [Open.Database.Extensions.Channel](https://www.nuget.org/packages/Open.Database.Extensions.Channel/) | Rows into `System.Threading.Channels`. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| **Open.Database.Extensions.Dataflow** (this package) | Rows into TPL Dataflow blocks. | netstandard2.0, netstandard2.1, net10.0, net11.0 |

Each of the other packages brings Core with it. .NET 8 and .NET 9 use the netstandard2.1 build.

[Documentation](https://open-net-libraries.github.io/Open.Database.Extensions/) · [API reference](https://open-net-libraries.github.io/Open.Database.Extensions/api/index.html) · [Source and issues](https://github.com/Open-NET-Libraries/Open.Database.Extensions) · MIT license
7 changes: 2 additions & 5 deletions Source/Extensions/Open.Database.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>
Useful set of utilities and abstractions for simplifying modern data-access operations and ensuring DI compatibility.
This is simply a meta-package that includes Open.Database.Extensions.Core.
</Description>
<PackageTags>ado;ado extensions;sql;connection factory;extensions;</PackageTags>
<Description>Meta-package that installs Open.Database.Extensions.Core: you write the SQL and it writes the ADO.NET around it, with queries defined once, rows mapped to your types by row readers written at build time, and any ADO.NET provider. On SQL Server use Open.Database.Extensions.MSSqlClient.</Description>
<PackageTags>open-database-extensions;ado.net;adonet;sql;database;data-access;dbconnection;mapping;stored-procedure;connection-factory;extensions;meta-package</PackageTags>
</PropertyGroup>

<ItemGroup>
Expand Down
70 changes: 68 additions & 2 deletions Source/Extensions/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
# Open.Database.Extensions

**This meta-package is discontinued.** Install [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) directly.
[![Open.Database.Extensions: You write the SQL. ODX writes the other twenty lines.](https://raw.githubusercontent.com/Open-NET-Libraries/Open.Database.Extensions/master/docsite/images/hero-core.svg)](https://open-net-libraries.github.io/Open.Database.Extensions/)

[Documentation](https://open-net-libraries.github.io/Open.Database.Extensions/) · [Source and issues](https://github.com/Open-NET-Libraries/Open.Database.Extensions) · MIT license
You write the SQL. Open.Database.Extensions (ODX) writes the ADO.NET around it: the connection, the parameters, the read loop, the mapping to your types and the disposal. It works with any ADO.NET provider and holds a connection open only while a query needs it.

This is the package named `Open.Database.Extensions`, and installing it is a supported way to use the library: it brings [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) and nothing else, so it is the same library as installing Core directly.

```sh
dotnet add package Open.Database.Extensions
dotnet add package Microsoft.Data.Sqlite # your provider; SQLite is used below
```

## Which package do I install?

| You use | Install |
|---|---|
| Any ADO.NET provider | `Open.Database.Extensions` (this package) or [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/): the same library, plus the provider you already use. |
| SQL Server | [Open.Database.Extensions.MSSqlClient](https://www.nuget.org/packages/Open.Database.Extensions.MSSqlClient/): it brings Core and `Microsoft.Data.SqlClient`, and targets `net472`, `net10.0` and `net11.0`. |
| Rows into channels | Add [Open.Database.Extensions.Channel](https://www.nuget.org/packages/Open.Database.Extensions.Channel/). |
| Rows into TPL Dataflow | Add [Open.Database.Extensions.Dataflow](https://www.nuget.org/packages/Open.Database.Extensions.Dataflow/). |

## Define a query once

```cs
using System.Data.Common;
using Open.Database.Extensions;

public record Post(int Id, string Title);

public class PostQueries(IDbConnectionFactory<DbConnection> connectionFactory)
{
// Declared once: immutable, with no connection, safe in a static field.
// Assumes a table posts(id, author, title).
static readonly MappedDbQuery<Post> ByAuthor
= DbQuery.Text("select id, title from posts where author = @author")
.Map<Post>();

// Opens a connection, reads every row, then disposes the connection.
public ValueTask<Post[]> ByAuthorAsync(
int author,
CancellationToken cancellationToken)
=> ByAuthor.Using(connectionFactory)
.AddParam(author) // name and type inferred from the variable
.ToArrayAsync(cancellationToken);
}
```

Create the factory once per application, with your provider's connection type:

```cs
using Microsoft.Data.Sqlite;

// connectionString, for example "Data Source=blog.db"
var connectionFactory = new DbConnectionFactory<SqliteConnection>(
() => new SqliteConnection(connectionString));
```

## The packages

| Package | What it adds | Targets |
|---|---|---|
| [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) | Expressive commands, `DbQuery` and `Map<T>()`, for any ADO.NET provider. Start here. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| **Open.Database.Extensions** (this package) | Installs Core and nothing else: the same library under the shorter name. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.MSSqlClient](https://www.nuget.org/packages/Open.Database.Extensions.MSSqlClient/) | `SqlConnectionFactory` and SQL Server on `Microsoft.Data.SqlClient`. | net472, net10.0, net11.0 |
| [Open.Database.Extensions.Channel](https://www.nuget.org/packages/Open.Database.Extensions.Channel/) | Rows into `System.Threading.Channels`. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.Dataflow](https://www.nuget.org/packages/Open.Database.Extensions.Dataflow/) | Rows into TPL Dataflow blocks. | netstandard2.0, netstandard2.1, net10.0, net11.0 |

Each of the other packages brings Core with it. .NET 8 and .NET 9 use the netstandard2.1 build.

[Documentation](https://open-net-libraries.github.io/Open.Database.Extensions/) · [Getting started](https://open-net-libraries.github.io/Open.Database.Extensions/articles/getting-started.html) · [Coming from Dapper](https://open-net-libraries.github.io/Open.Database.Extensions/articles/coming-from-dapper.html) · [Performance](https://open-net-libraries.github.io/Open.Database.Extensions/articles/performance.html) · [API reference](https://open-net-libraries.github.io/Open.Database.Extensions/api/index.html) · [Source and issues](https://github.com/Open-NET-Libraries/Open.Database.Extensions) · MIT license
12 changes: 11 additions & 1 deletion Source/MSSqlClient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ To read rows and outputs from one call, capture them with `CaptureOutput(out DbC
- **Give a procedure its schema** (`[dbo].[SearchPosts]`): its parameter names are then read once per server and database. A name without one is kept per connection factory, so keep one factory for the application.
- **`AddParams(source)` sends every member the procedure declares.** Pass an object you trust, and add a value only the server should decide with `AddParam("name", value)`.

The other packages are listed on [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/).
## The packages

| Package | What it adds | Targets |
|---|---|---|
| [Open.Database.Extensions.Core](https://www.nuget.org/packages/Open.Database.Extensions.Core/) | Expressive commands, `DbQuery` and `Map<T>()`, for any ADO.NET provider. Start here. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions](https://www.nuget.org/packages/Open.Database.Extensions/) | Installs Core and nothing else: the same library under the shorter name. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| **Open.Database.Extensions.MSSqlClient** (this package) | `SqlConnectionFactory` and SQL Server on `Microsoft.Data.SqlClient`. | net472, net10.0, net11.0 |
| [Open.Database.Extensions.Channel](https://www.nuget.org/packages/Open.Database.Extensions.Channel/) | Rows into `System.Threading.Channels`. | netstandard2.0, netstandard2.1, net10.0, net11.0 |
| [Open.Database.Extensions.Dataflow](https://www.nuget.org/packages/Open.Database.Extensions.Dataflow/) | Rows into TPL Dataflow blocks. | netstandard2.0, netstandard2.1, net10.0, net11.0 |

Each of the other packages brings Core with it. .NET 8 and .NET 9 use the netstandard2.1 build.

[Documentation](https://open-net-libraries.github.io/Open.Database.Extensions/) · [API reference](https://open-net-libraries.github.io/Open.Database.Extensions/api/index.html) · [Source and issues](https://github.com/Open-NET-Libraries/Open.Database.Extensions) · MIT license
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
dotnet pack Source/Core -c Release -o <feed> -p:VersionSuffix=<unique> -p:GeneratePackageOnBuild=false (and Source/MSSqlClient)
dotnet test Tests/Open.Database.Extensions.PackageConsumer.Tests -p:OdxFeed=<feed> -p:OdxPackageVersion=<version>-<unique>

-p:OdxVia=MSSqlClient references that package alone, so Core and its generator arrive transitively. -p:OdxGenerateMaps=false switches the
generator off.
-p:OdxVia=MSSqlClient references that package alone, so Core and its generator arrive transitively; -p:OdxVia=Extensions does the same with the
Open.Database.Extensions meta-package (pack Source/Extensions too). -p:OdxGenerateMaps=false switches the generator off.
-->
<PropertyGroup>
<TargetFrameworks>net472;net11.0</TargetFrameworks>
Expand All @@ -23,6 +23,9 @@
<!-- SQLite's native library is loaded by the process's bitness, which .NET Framework would otherwise choose as 32-bit. -->
<PlatformTarget Condition="'$(TargetFramework)' == 'net472'">x64</PlatformTarget>
<OdxVia Condition="'$(OdxVia)' == ''">Core</OdxVia>
<!-- The package id: Open.Database.Extensions.Core, .MSSqlClient and so on, or the meta-package, which has no suffix. -->
<OdxPackageId>Open.Database.Extensions.$(OdxVia)</OdxPackageId>
<OdxPackageId Condition="'$(OdxVia)' == 'Extensions'">Open.Database.Extensions</OdxPackageId>
<RestoreAdditionalProjectSources>$(OdxFeed)</RestoreAdditionalProjectSources>
<!-- Test-only: the generated code counts what it served. -->
<OdxGeneratorCounters>true</OdxGeneratorCounters>
Expand All @@ -36,8 +39,8 @@

<ItemGroup>
<!-- The package under test is not in Directory.Packages.props: its version comes from the command line. -->
<PackageVersion Include="Open.Database.Extensions.$(OdxVia)" Version="$(OdxPackageVersion)" />
<PackageReference Include="Open.Database.Extensions.$(OdxVia)" />
<PackageVersion Include="$(OdxPackageId)" Version="$(OdxPackageVersion)" />
<PackageReference Include="$(OdxPackageId)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Data.Sqlite" />
<PackageReference Include="Microsoft.Data.SqlClient" />
Expand Down
Loading