Sequel 3.1.4

.NET Standard 2.0
NuGet\Install-Package Sequel -Version 3.1.4
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.
dotnet add package Sequel --version 3.1.4
<PackageReference Include="Sequel" Version="3.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sequel --version 3.1.4
#r "nuget: Sequel, 3.1.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sequel as a Cake Addin
#addin nuget:?package=Sequel&version=3.1.4

// Install Sequel as a Cake Tool
#tool nuget:?package=Sequel&version=3.1.4

Sequel

NuGet Version build

An efficient SQL builder with an interface that emulates writing actual SQL queries.

Getting Started

SELECT

var sqlBuilder = new SqlBuilder()
  .Select("Id", "Salary")
  .From("dbo.Test");

var sql = sqlBuilder.ToSql(); // .ToString() also works

/*
SELECT Id, Salary FROM dbo.Test
*/

// SELECT with INNER & LEFT JOIN
var sqlBuilder = new SqlBuilder()
  .Select("*")
  .From("dbo.Test t")
  .Join("dbo.Employee e on e.Id = t.EmployeeId")
  .LeftJoin("dbo.Manager m on m.Id = e.ManagerId");

var sql = sqlBuilder.ToSql();

/*
SELECT * FROM dbo.Test t INNER JOIN dbo.Employee e on e.Id = t.EmployeeId LEFT JOIN dbo.Manager m on m.Id = e.ManagerId
*/

INSERT

var sqlBuilder = new SqlBuilder()
  .Insert("dbo.Test")
  .Columns("Name", "Salary")
  .Values("'John'", "50")
  .Values("'Jane'", "100");

var sql = sqlBuilder.ToSql(); // .ToString() also works

/*
INSERT INTO dbo.Test (Name, Salary) VALUES ('John', 50), ('Jane', 100)
*/

UPDATE

var sqlBuilder = new SqlBuilder()
  .Update("dbo.Test")
  .Set("Salary = 100", "ManagerId = 2")
  .Where("EmployeeId = 1");

var sql = sqlBuilder.ToSql(); // .ToString() also works

/*
UPDATE dbo.Test SET Salary = 100, ManagerId = 2 WHERE EmployeeId = 1
*/

DELETE

var sqlBuilder = new SqlBuilder()
  .Delete()
  .From("dbo.Test")
  .Where("EmployeeId = 1");

var sql = sqlBuilder.ToSql(); // .ToString() also works

/*
DELETE FROM dbo.Test WHERE EmployeeId = 1
*/

Injecting custom SQL

You are granted pre- & post-hooks into the final SQL string literaly, for the purpose of injecting custom SQL.

The pre-hook is useful in the case of CTE's or inline declarations.

var sqlBuilder = new SqlBuilder(pre: "WITH cte AS (SELECT 1) ")
  .Select("*")
  .From("cte");

var sql = sqlBuilder.ToSql();

/*
WITH cte AS (SELECT 1) SELECT * FROM cte"
*/

The post-hook is useful for situations like obtaining the last inserted row identifier.

var sqlBuilder = new SqlBuilder(post: "; SELECT last_insert_rowid();")
  .Insert("dbo.Test")
  .Into("Name", "Salary")
  .Value("'Pim'", "50");

var sql = sqlBuilder.ToSql();

/*
INSERT INTO dbo.Test (Name, Salary) VALUES ('Pim', 50); SELECT last_insert_rowid();
*/

An example using Dapper

using(var conn = new SqlConnection("your connection string")
{
  var sqlBuilder = new SqlBuilder()
    .Select("Id", "Salary")
    .From("dbo.Test")
    .Where("Id", "@Id");

  var sql = sqlBuilder.ToSql(); // .ToString() also works
  /*
  SELECT Id, Salary FROM dbo.Test WHERE Id = @Id
  */

  var result = conn.Query(sql, new { Id = 1 });
}

Find a bug?

There's an issue for that.

License

Built with ♥ by NHLPA Engineering in Toronto, ON. Licensed under MIT.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Sequel:

Package Downloads
LunchPail.Repository

A .NET Standard compliant abstract repository for use with LunchPail.

NBean

Hybrid-ORM for .Net

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.4 46 9/16/2022
3.1.3 44 9/16/2022
3.1.2 43 9/16/2022
3.1.1 281 7/31/2021
3.1.0 313 12/4/2020
3.0.2 251 11/30/2020
3.0.1 306 11/15/2020
3.0.0 219 11/14/2020
2.0.0 990 10/28/2019
1.1.5 565 3/20/2019
1.1.4 422 3/5/2019
1.1.3 873 8/31/2018
1.1.2 589 8/24/2018
1.1.1 566 8/24/2018
1.1.0 566 8/23/2018
1.0.6 561 8/23/2018
1.0.5 1,700 8/21/2018
1.0.4 828 7/26/2018
1.0.3 584 7/25/2018
1.0.2 692 5/5/2018
1.0.1 674 5/5/2018
1.0.0 623 5/2/2018