UkrGuru.SqlJson
9.0.2
See the version list below for details.
dotnet add package UkrGuru.SqlJson --version 9.0.2
NuGet\Install-Package UkrGuru.SqlJson -Version 9.0.2
<PackageReference Include="UkrGuru.SqlJson" Version="9.0.2" />
paket add UkrGuru.SqlJson --version 9.0.2
#r "nuget: UkrGuru.SqlJson, 9.0.2"
// Install UkrGuru.SqlJson as a Cake Addin #addin nuget:?package=UkrGuru.SqlJson&version=9.0.2 // Install UkrGuru.SqlJson as a Cake Tool #tool nuget:?package=UkrGuru.SqlJson&version=9.0.2
UkrGuru.SqlJson
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:
- 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 | 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. |
-
net8.0
- Microsoft.Data.SqlClient (>= 5.2.2)
- UkrGuru.SqlJson.Client (>= 9.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.
Added support many input sql params. Added new method IAsyncEnumerable<T> ReadListAsync<T>().