UkrGuru.SqlJson 9.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package UkrGuru.SqlJson --version 9.2.0                
NuGet\Install-Package UkrGuru.SqlJson -Version 9.2.0                
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="UkrGuru.SqlJson" Version="9.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UkrGuru.SqlJson --version 9.2.0                
#r "nuget: UkrGuru.SqlJson, 9.2.0"                
#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.
// Install UkrGuru.SqlJson as a Cake Addin
#addin nuget:?package=UkrGuru.SqlJson&version=9.2.0

// Install UkrGuru.SqlJson as a Cake Tool
#tool nuget:?package=UkrGuru.SqlJson&version=9.2.0                

UkrGuru.SqlJson

Nuget Donate

UkrGuru.SqlJson is a library that makes it easy to interact between .NET applications and SQL Server databases. Supports CRUD with or without API with the same interface. It allows developers to automatically normalize input parameters and deserialize the result. Also supports dynamic queries, stored procedures and asynchronous operations. With the UkrGuru.SqlJson package, you can access SQL Server data with minimal code and maximum performance.

Installation

To use UkrGuru SqlJson library in your ASP.NET Core project, you need to follow these steps:

1. Install the UkrGuru.SqlJson package from NuGet.

2. Open the AppSettings.json files and add the "UkrGuru.SqlJson" and "DefaultConnection" elements.

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=BlazorAppDemo;Trusted_Connection=True;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

2. Open the Program.cs file and register the UkrGuru SqlJson services and extensions:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSqlJson(builder.Configuration.GetConnectionString("DefaultConnection"));

// More other services here ... 

var app = builder.Build();

Samples of code

@code {
    public List<ProductDto>? Products { get; set; }

    protected override async Task InitData() { Title ??= "Products"; await Task.CompletedTask; }

    protected override async Task LoadData() {
        Products = await db.ReadAsync<List<ProductDto>>("Products_Grd");
    }

    protected override async Task InsItemAsync(GridCommandEventArgs args) 
        => await db.CreateAsync<int?>("Products_Ins", (ProductDto)args.Item);

    protected override async Task UpdItemAsync(GridCommandEventArgs args) 
        => await db.UpdateAsync("Products_Upd", (ProductDto)args.Item);

    protected override async Task DelItemAsync(GridCommandEventArgs args) 
        => await db.DeleteAsync("Products_Del", ((ProductDto)args.Item)?.ProductId);
}

Standard for procedures

UkrGuru.SqlJson automatically normalizes input parameters and deserializes the result.

Requirements:

  1. INPUT: You can use any query or procedure that has only one @Data parameter, or no parameter at all. UkrGuru.SqlJson will auto serialize the complex parameter to JSON format.
  2. OUTPUT: You should format the result as a single column SELECT statement.
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

CREATE OR ALTER PROCEDURE [Products_Del]
    @Data int
AS
DELETE Products
WHERE ProductId = @Data
GO

CREATE OR ALTER PROCEDURE [Products_Get]
    @Data int
AS
SELECT *
FROM Products
WHERE ProductId = @Data
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
GO

CREATE OR ALTER PROCEDURE [Products_Grd]
AS
SELECT *
FROM Products
FOR JSON PATH
GO

CREATE OR ALTER PROCEDURE [Products_Ins]
	@Data nvarchar(500)  
AS
INSERT INTO Products 
SELECT * FROM OPENJSON(@Data) 
WITH (ProductName varchar(50), CategoryName varchar(20), QuantityPerUnit varchar(20), 
	UnitPrice smallmoney, UnitsInStock int, UnitsOnOrder int, ReorderLevel int, Discontinued bit)

SELECT SCOPE_IDENTITY()
GO

CREATE OR ALTER PROCEDURE [Products_Upd]
	@Data nvarchar(500)  
AS
UPDATE Products
SET ProductName = D.ProductName, CategoryName = D.CategoryName, QuantityPerUnit = D.QuantityPerUnit,
	UnitPrice = D.UnitPrice, UnitsInStock = D.UnitsInStock, UnitsOnOrder = D.UnitsOnOrder,
	ReorderLevel = D.ReorderLevel, Discontinued = D.Discontinued
FROM OPENJSON(@Data) 
WITH (ProductId int, ProductName varchar(50), CategoryName varchar(20), QuantityPerUnit varchar(20), 
	UnitPrice smallmoney, UnitsInStock int, UnitsOnOrder int, ReorderLevel int, Discontinued bit) D
WHERE Products.ProductId = D.ProductId
GO
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 is compatible. 
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 UkrGuru.SqlJson:

Package Downloads
UkrGuru.WebJobs

The UkrGuru.WebJobs package is a Scheduler and N-Workers for any base( or custom) Actions in .NET apps. Supports CRON expressions in Rules. Supports polymorphism for Action/Rule/Job parameters and transferring the result of the Job to the next Job, based on the results of the current Job. Uses UkrGuru.SqlJson to quickly run stored procedures on sql server.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.4.0 32 12/26/2024
9.2.1 81 12/23/2024
9.2.0 80 12/19/2024
9.1.0 82 11/27/2024
9.0.3 109 10/11/2024
9.0.2 121 8/29/2024
9.0.0 120 6/14/2024
8.8.1 134 6/1/2024
8.5.4 141 3/12/2024
7.2.1 148 2/10/2024
6.7.7 554 11/2/2023
6.7.6 309 10/25/2023
6.7.5 458 10/22/2023
6.7.2 329 10/9/2023
6.7.0 321 10/6/2023
6.5.0 657 7/23/2023

Added support many input sql params. Added new method IAsyncEnumerable<T> ReadListAsync<T>().