Naravel.Database
0.2.0
dotnet add package Naravel.Database --version 0.2.0
NuGet\Install-Package Naravel.Database -Version 0.2.0
<PackageReference Include="Naravel.Database" Version="0.2.0" />
<PackageVersion Include="Naravel.Database" Version="0.2.0" />
<PackageReference Include="Naravel.Database" />
paket add Naravel.Database --version 0.2.0
#r "nuget: Naravel.Database, 0.2.0"
#:package Naravel.Database@0.2.0
#addin nuget:?package=Naravel.Database&version=0.2.0
#tool nuget:?package=Naravel.Database&version=0.2.0
Naravel.Database
Laravel-style query builder for Naravel on ADO.NET and Dapper: named connections on Naravel.Foundation, a connection and transaction seam that EF Core can share, and per-database driver packages.
| Fact | Detail |
|---|---|
| Install | dotnet add package Naravel.Database |
| Targets | .NET 10 |
| Needs | Naravel.Foundation and Naravel.Pagination, which NuGet installs with it |
| Drivers | SQLite, MySQL, PostgreSQL and SQL Server, one package each (listed below) |
What you get
- A fluent query builder on ADO.NET and Dapper:
db.Table("users").Where("active", true).OrderBy("name"), with the values bound as parameters. - Named connections.
Defaultnames the connectionIDatabaseuses anddb.Connection("reports")gives another, so one application can use several databases. - Four databases. The
Driverof a connection issqlite,mysql,pgsqlorsqlserver, and each value has its own driver package. - One transaction with EF Core. With
Naravel.Database.EntityFrameworkCore, aDbContextwrite and a query-builder write commit or roll back together. - Raw SQL and a query log.
?placeholders become bound parameters, and the opt-inAddNaravelDatabaseQueryLog()keeps the last queries for development and tests.
Quick start
The connection Driver picks a driver package, which you install next to this one; the sample uses SQLite:
dotnet add package Naravel.Database.Sqlite
{ "Database": { "Default": "main", "Connections": { "main": { "Driver": "sqlite", "Path": "app.db" } } } }
using Naravel.Database;
builder.Services.AddNaravelDatabase(builder.Configuration); // reads the "Database" section and registers IDatabase for the default connection
builder.Services.AddNaravelSqliteDatabase(builder.Configuration); // the driver package that the Driver of the connection names; this package has none
public sealed class UserService(IDatabase db)
{
public Task<IReadOnlyList<IReadOnlyDictionary<string, object?>>> ActiveAsync(CancellationToken ct) =>
db.Table("users").Where("active", true).OrderBy("name").GetAsync(ct);
}
Rows come back as dictionaries, or as your own type with GetAsync<T>(), which maps through Dapper and is not trim or AOT safe. Raw SQL goes through db.SelectAsync(sql, bindings, ct) with ? placeholders, each one bound as a parameter.
Related packages
| Package | Adds |
|---|---|
Naravel.Database.EntityFrameworkCore |
A DbContext and the query builder share one connection and one transaction |
Naravel.Database.MySql |
MySQL driver on MySqlConnector |
Naravel.Database.Postgres |
PostgreSQL driver on Npgsql |
Naravel.Database.SqlServer |
SQL Server driver on Microsoft.Data.SqlClient |
Naravel.Database.Sqlite |
SQLite driver on Microsoft.Data.Sqlite |
Learn more
- Database: English guide
- Changelog · Source and issues · MIT license
Part of Naravel: Laravel's names, .NET's type system. All Naravel packages share one version.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Dapper (>= 2.1.89)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.14)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.14)
- Microsoft.Extensions.Options (>= 10.0.14)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.14)
- Naravel.Foundation (>= 0.2.0)
- Naravel.Pagination (>= 0.2.0)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Naravel.Database:
| Package | Downloads |
|---|---|
|
Naravel.Database.Sqlite
SQLite driver for Naravel.Database, built on Microsoft.Data.Sqlite. |
|
|
Naravel.Database.Postgres
PostgreSQL driver for Naravel.Database, built on Npgsql. |
|
|
Naravel.Database.SqlServer
SQL Server driver for Naravel.Database, built on Microsoft.Data.SqlClient. |
|
|
Naravel.Database.MySql
MySQL driver for Naravel.Database, built on MySqlConnector. |
|
|
Naravel.Database.EntityFrameworkCore
EF Core interop for Naravel.Database: a DbContext and the query builder share one connection and one transaction. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Release notes: https://github.com/km-arc/Naravel/releases/tag/v0.2.0 - full history: https://github.com/km-arc/Naravel/blob/main/CHANGELOG.md