DBTools 1.4.3

dotnet add package DBTools --version 1.4.3
                    
NuGet\Install-Package DBTools -Version 1.4.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DBTools" Version="1.4.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DBTools" Version="1.4.3" />
                    
Directory.Packages.props
<PackageReference Include="DBTools" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DBTools --version 1.4.3
                    
#r "nuget: DBTools, 1.4.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DBTools@1.4.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DBTools&version=1.4.3
                    
Install as a Cake Addin
#tool nuget:?package=DBTools&version=1.4.3
                    
Install as a Cake Tool

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.

.NET Version NuGet License CI

Installation

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.

  1. 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
  1. 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

  1. Install DBTools (see Installation).
  2. Copy the example config and set your connection details:
cp DBTools/config.json.example config.json
  1. Ensure config.json is copied to your app's output directory (Visual Studio: Copy to Output Directory → Copy always).
  2. 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

License

This project is licensed under the MIT License.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.3 998 6/23/2026
1.4.2 84 6/23/2026
1.4.1 113 6/21/2026
1.4.0 110 6/19/2026