DBTools 1.4.1
See the version list below for details.
dotnet add package DBTools --version 1.4.1
NuGet\Install-Package DBTools -Version 1.4.1
<PackageReference Include="DBTools" Version="1.4.1" />
<PackageVersion Include="DBTools" Version="1.4.1" />
<PackageReference Include="DBTools" />
paket add DBTools --version 1.4.1
#r "nuget: DBTools, 1.4.1"
#:package DBTools@1.4.1
#addin nuget:?package=DBTools&version=1.4.1
#tool nuget:?package=DBTools&version=1.4.1
DBTools
A multi-provider .NET 8 database access library for SQL Server, PostgreSQL, MySQL, and SQLite — with parameterized CRUD, LINQ-style queries, JOINs, upsert, and built-in SQL injection protection.
Installation
From NuGet.org (recommended)
dotnet add package DBTools --version 1.4.1
Releases are published to nuget.org automatically when a v* tag is pushed (see Deployment).
From GitHub Packages
Releases are also published to GitHub Packages on every v* tag.
- Authenticate with a GitHub PAT that has
read:packages:
dotnet nuget add source "https://nuget.pkg.github.com/gednt/index.json" \
--name github \
--username YOUR_GITHUB_USERNAME \
--password YOUR_GITHUB_PAT \
--store-password-in-clear-text
- Install the package:
dotnet add package DBTools --version 1.4.1 --source github
Alternatively, copy nuget.config.github-packages.example to your solution as nuget.config and add credentials as described in that file.
Optional provider packages
SQL Server support is bundled via Microsoft.Data.SqlClient. For other providers, add the matching package to your application:
| Provider | Package |
|---|---|
| PostgreSQL | Npgsql |
| MySQL | MySqlConnector |
| SQLite | Microsoft.Data.Sqlite |
dotnet add package DBTools --version 1.4.1
dotnet add package Npgsql # only if using PostgreSQL
From source
git clone https://github.com/gednt/DBTools_SQL.git
cd DBTools_SQL
dotnet build DBTools.sln
Reference DBTools/DBTools.csproj from your project, or pack locally:
dotnet pack DBTools/DBTools.csproj -c Release -o ./artifacts
dotnet add package DBTools --source ./artifacts
Quick start
- Install
DBTools(see Installation). - Copy the example config and set your connection details:
cp DBTools/config.json.example config.json
- Ensure
config.jsonis copied to your app's output directory (Visual Studio: Copy to Output Directory → Copy always). - Query the database:
using DBTools.Core;
using System.Data;
var db = new SqlClient();
DataView users = db.Select(
"*",
"Users",
"Age > @param0",
new object[] { 18 }
);
foreach (DataRowView row in users)
{
Console.WriteLine($"{row["Name"]}, age {row["Age"]}");
}
Example config.json:
{
"Provider": "SqlServer",
"Host": "localhost\\SQLEXPRESS",
"Database": "YourDatabaseName",
"Uid": "YourUsername",
"Password": "YourPassword",
"Port": "1433"
}
Supported Provider values: SqlServer (default), PostgreSQL, MySQL, SQLite.
Usage examples
Parameterized CRUD with SqlClient
using DBTools.Core;
var db = new SqlClient();
// Insert
db.Insert(
new[] { "Name", "Email", "Age" },
"Users",
new object[] { "Jane Doe", "jane@example.com", 30 }
);
// Update
db.Update(
new[] { "Email" },
"Users",
new[] { "new@example.com" },
"Id = @whereParam0",
new object[] { 1 }
);
// Delete
db.Delete("Users", "Id = @param0", new object[] { 1 });
LINQ-style queries with LinqHelper<T>
using DBTools.Controllers;
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
var users = new LinqHelper<User>("Users", "Id", autoIncrement: true);
var adults = users.Where(u => u.Age > 18);
users.Add(new User { Name = "Alice", Age = 28 });
users.Remove(u => u.Id == 5);
For property-based filters (WhereContains, WhereBetween), JOINs, and deferred IQueryable execution, use Linq<T> instead. See docs/EXAMPLES.md.
Async LINQ with AsyncLinqHelper<T>
For async CRUD with lambda predicates, attribute-based table mapping, and query interceptors, use AsyncLinqHelper<T> on top of AsyncSqlClient:
using DBTools.Controllers;
using DBTools.Core;
using DBTools.Mapping;
[Table("Users")]
public class User
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
var client = new AsyncSqlClient();
var users = new AsyncLinqHelper<User>(client);
var adults = await users.WhereAsync(u => u.Age > 18);
await users.InsertAsync(new User { Name = "Alice", Age = 28 });
await users.RemoveAsync(u => u.Id == 5);
With DI, inject IAsyncSqlClient and pass it to the constructor. See docs/API_REFERENCE.md and docs/EXAMPLES.md.
Dependency injection
using DBTools.Configuration;
services.AddDbTools(options =>
{
options.Provider = DatabaseProvider.PostgreSQL;
options.Host = "localhost";
options.Port = "5432";
options.Database = "myappdb";
options.Username = "postgres";
options.Password = "secret";
});
// Inject IAsyncSqlClient or SqlClient in your services
Documentation
- Quick Start Guide — step-by-step tutorial
- Examples — comprehensive code samples
- API Reference — method-level documentation
- Security — SQL injection prevention and best practices
License
This project is licensed under the MIT License (see PackageLicenseExpression in DBTools/DBTools.csproj).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.1)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.1)
- Microsoft.Extensions.Configuration.Json (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.FileProviders.Abstractions (>= 10.0.1)
- Microsoft.Extensions.FileProviders.Physical (>= 10.0.1)
- Microsoft.Extensions.FileSystemGlobbing (>= 10.0.1)
- Microsoft.Extensions.Primitives (>= 10.0.1)
- NPOI (>= 2.7.3)
- Portable.BouncyCastle (>= 1.9.0)
- SharpZipLib (>= 1.4.2)
- System.Configuration.ConfigurationManager (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.