UkrGuru.SqlJson
6.5.0
See the version list below for details.
dotnet add package UkrGuru.SqlJson --version 6.5.0
NuGet\Install-Package UkrGuru.SqlJson -Version 6.5.0
<PackageReference Include="UkrGuru.SqlJson" Version="6.5.0" />
paket add UkrGuru.SqlJson --version 6.5.0
#r "nuget: UkrGuru.SqlJson, 6.5.0"
// Install UkrGuru.SqlJson as a Cake Addin #addin nuget:?package=UkrGuru.SqlJson&version=6.5.0 // Install UkrGuru.SqlJson as a Cake Tool #tool nuget:?package=UkrGuru.SqlJson&version=6.5.0
UkrGuru.SqlJson
UkrGuru.SqlJson is a library that simplifies the interaction between .NET applications and SQL Server databases. It allows developers to automatically normalize input parameters and deserialize the result. Also supports dynamic queries, stored procedures and asynchronous operations. With UkrGuru.SqlJson, 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:
- 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.
- 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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 was computed. 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. |
-
net6.0
- Microsoft.Data.SqlClient (>= 5.1.1)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
-
net7.0
- Microsoft.Data.SqlClient (>= 5.1.1)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
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.
Code optimization and minimization