ShadowSql 0.8.0.3-alpha

This is a prerelease version of ShadowSql.
dotnet add package ShadowSql --version 0.8.0.3-alpha
                    
NuGet\Install-Package ShadowSql -Version 0.8.0.3-alpha
                    
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="ShadowSql" Version="0.8.0.3-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ShadowSql" Version="0.8.0.3-alpha" />
                    
Directory.Packages.props
<PackageReference Include="ShadowSql" />
                    
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 ShadowSql --version 0.8.0.3-alpha
                    
#r "nuget: ShadowSql, 0.8.0.3-alpha"
                    
#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.
#addin nuget:?package=ShadowSql&version=0.8.0.3-alpha&prerelease
                    
Install ShadowSql as a Cake Addin
#tool nuget:?package=ShadowSql&version=0.8.0.3-alpha&prerelease
                    
Install ShadowSql as a Cake Tool

ShadowSql

  • 拼接sql工具,支持多种数据库,包括MsSql,MySql,Oracle,Sqlite,Postgres等
  • 整个sql拼写只使用1个StringBuilder,减少字符串碎片生成

以下简单示例的sql是按MsSql数据库

1. 按列名查询

var query = _db.From("Users")
    .ToSqlQuery()
    .ColumnParameter("Id", "<", "LastId")
    .ColumnValue("Status", true);

SELECT * FROM [Users] WHERE [Id]<@LastId AND [Status]=1

2. 按列查询

var query = new UserTable()
    .ToSqlQuery()
     .Where(table => table.Id.Less("LastId"))
     .Where(table => table.Status.EqualValue(true));

SELECT * FROM [Users] WHERE [Id]<@LastId AND [Status]=1

3. 原生sql查询

var query = _db.From("Users")
    .ToSqlQuery()
    .Where("Id=@Id", "Status=@Status");

SELECT * FROM [Users] WHERE Id=@Id AND Status=@Status

4. 逻辑运算查询

var users = new UserTable();
var query = users.ToQuery()
    .And(users.Id.Less("LastId") & users.Status.EqualValue(true));

SELECT * FROM [Users] WHERE [Id]<@LastId AND [Status]=1

5. 分页查询

var query = new UserTable()
    .ToSqlQuery()
    .Where(table => table.Id.Less("LastId"))
    .Where(table => table.Status.EqualValue(true))
    .ToCursor()
    .Desc(table => table.Id)
    .Skip(10)
    .Take(10);

SELECT * FROM [Users] WHERE [Id]<@LastId AND [Status]=1 ORDER BY [Id] DESC OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY

6. 连接查询

var e = SimpleDB.From("Employees").As("e");
var d = SimpleDB.From("Departments").As("d");
var joinOn = e.SqlJoin(d)
    .On(e.Field("DepartmentId").Equal(d.Field("Id")));
var joinTable = joinOn.Root
    .Where(e.Field("Age").GreaterValue(30))
    .Where(d.Field("Manager").EqualValue("CEO"));

SELECT * FROM [Employees] AS e INNER JOIN [Departments] AS d ON e.[DepartmentId]=d.[Id] WHERE e.[Age]>30 AND d.[Manager]='CEO'

7. 删除

var delete = new StudentTable()
    .ToSqlQuery()
    .Where(table => table.Score.LessValue(60))
    .ToDelete();

DELETE FROM [Students] WHERE [Score]<60

8. 更新

var update = new StudentTable()
    .ToSqlQuery()
    .Where(table => table.Score.LessValue(60))
    .ToUpdate()
    .Set(table => table.Score.AddValue(10));

UPDATE [Students] SET [Score]+=10 WHERE [Score]<60

9. 插入

var insert = new StudentTable()
    .ToInsert()
    .Insert(student => student.Name.Insert("StudentName"))
    .Insert(student => student.Score.InsertValue(90));
INSERT INTO [Students]([Name],[Score])VALUES(@StudentName,90)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ShadowSql:

Package Downloads
ShadowSql.Dapper

ShadowSql的Dapper扩展

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.0.3-alpha 90 4/13/2025
0.8.0.2-alpha 54 4/12/2025
0.8.0.1-alpha 82 4/11/2025
0.7.0.1-alpha 125 4/8/2025
0.7.0-alpha 84 4/4/2025