SqlOrder 0.0.4

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

SQLOrder

SQLOrder is a .Net library that analyzes SQL files for dependencies so they can be run in the correct order. Targets MS SQL Server.

For instance, let's say you have these two files:

-- someTable.sql

create table someTable (
    id int not null
);
-- someProc.sql

create procedure someProc
    as
begin
select * from someTable;
end;

If you run these two scripts in the wrong order, you'll get an error since someTable won't exist.

SQLOrder will analyze the SQL files you give it, build a dependency graph, and give you back the files in the correct order so that you can easily build your schema from raw SQL files without needing to manually keep up with the dependencies:

using SqlOrder;

var sqlFiles = new[] {
    // likely you'll want to do a filesystem enumeration or something here
    new FileScript("someTable.sql"),
    new FileScript("someProc.sql"),
};

var orderer = new ScriptOrderer();
var results = await orderer.OrderScripts(sqlFiles, CancellationToken.None);

SqlOrder understands dependencies on:

  • Schemas
  • Tables and views
  • User-defined functions
  • Stored procedures
  • User-defined data types
  • Sequences

User-defined Dependencies

In some cases, SqlOrder may not notice or understand a dependency. In those cases, it would cause the ordering it provides to be incorrect, meaning that running the SQL files in the order that SqlOrder provides would produce an error from SQL Server. If you need to work around a situation like this, you can add user-defined dependencies to the dependency model:


var sqlFilesByName = new[] {
        // your files here
    }
    .ToDictionary(x => x.Name);

var orderer = new ScriptOrderer();

// badResults incorrectly has "scriptA.sql" first even though it depends on
// something in "scriptB.sql".
var badResults = await orderer.OrderScripts(sqlFilesByName.Values, CancellationToken.None);

var model = await orderer.BuildModel();
model.AddDependency(
    predecessor: sqlFilesByName["scriptB.sql"],
    successor: sqlFilesByName["scriptA.sql"],
);

var goodResults = model.All;
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
0.0.4 92 12/27/2024
0.0.3 94 12/19/2024
0.0.2 90 12/17/2024
0.0.1 92 12/17/2024