UkrGuru.SqlJson 8.8.1

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

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

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. 
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.0.3 89 10/11/2024
9.0.2 111 8/29/2024
9.0.0 110 6/14/2024
8.8.1 126 6/1/2024
8.5.4 137 3/12/2024
7.2.1 140 2/10/2024
6.7.7 531 11/2/2023
6.7.6 305 10/25/2023
6.7.5 454 10/22/2023
6.7.2 323 10/9/2023
6.7.0 317 10/6/2023
6.5.0 651 7/23/2023

Split in 2 projects (UkrGuru.SqlJson and UkrGuru.SqlJson.Client).